{"id":1651,"date":"2009-03-03T03:44:35","date_gmt":"2009-03-03T10:44:35","guid":{"rendered":"http:\/\/kodegeek.com\/blog\/?p=1651"},"modified":"2009-03-03T03:45:35","modified_gmt":"2009-03-03T10:45:35","slug":"facebook-puzzles-ii-hoppity","status":"publish","type":"post","link":"http:\/\/kodegeek.com\/blog\/2009\/03\/03\/facebook-puzzles-ii-hoppity\/","title":{"rendered":"Facebook puzzles: (II, Hoppity)"},"content":{"rendered":"<p>Un <a href=\"http:\/\/www.facebook.com\/jobs_puzzles\/index.php?puzzle_id=6#\/jobs_puzzles\/index.php?puzzle_id=7\">nuevo rompecabezas<\/a>, un poco m\u00e1s complicado:<\/p>\n<pre lang=\"Java\">package com.kodegeek.blog.jobsearch.facebook.hoppity;\r\n\r\nimport java.io.BufferedReader;\r\nimport java.io.File;\r\nimport java.io.FileReader;\r\nimport java.io.IOException;\r\n\r\n\/**\r\n * To help test whether your puzzle submissions fit the guidelines, try this simple test puzzle.\r\n * Your solution must follow the guidelines like any other puzzle.\r\n * Write a program that takes as input a single argument on the command line.\r\n * This argument must be a file name, which contains a single positive integer.\r\n * The program should read this file and obtain the integer within, and then output a sequence of strings\r\n * based upon the number (details below).\r\n * @author josevnz@kodegeek.com\r\n *\r\n *\/\r\npublic final class Hoppity {\r\n\r\n\t\/**\r\n\t * The input file will contain a single positive integer (in base 10) expressed as a string using standard ASCII text\r\n\t * (e.g. for example, the number \"15\" but without the double quotes).\r\n\t * This number may or may not be padded on either side with white space.\r\n\t * There will be no commas, periods, or any other non-numeric characters present within the number.\r\n\t * The file may or may not terminate in a single new line character (\"\\n\")\r\n\t * @param file file with the number\r\n\t * @return integer\r\n\t * @throws IOException\r\n\t *\/\r\n\tprivate static int readNumber(File file) throws IOException {\r\n\t\tint aNumber = -1;\r\n\t\tBufferedReader reader = null;\r\n\t\ttry {\r\n\t\t\treader = new BufferedReader(new FileReader(file));\r\n\t\t\t\/\/ Trim any spaces and then try to parse the number\r\n\t\t\taNumber = Integer.parseInt(reader.readLine().replaceAll(\"\\\\s*\", \"\"));\r\n\t\t} catch (IOException ioExp) {\r\n\t\t\tthrow ioExp;\r\n\t\t} finally {\r\n\t\t\tif (reader != null) {\r\n\t\t\t\treader.close();\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn aNumber;\r\n\t}\r\n\r\n\t\/**\r\n\t * @param args args[0] = Full path to input file\r\n\t *\/\r\n\tpublic static void main(String[] args) throws Exception {\r\n\t\tif (args != null &amp;&amp; args.length == 1 &amp;&amp; args[0] != null) {\r\n\t\t\tFile numFile = new File(args[0]);\r\n\t\t\tif (numFile.exists() &amp;&amp; numFile.canRead()) {\r\n\t\t\t\tint number = readNumber(numFile);\r\n\t\t\t\tfor (int i = 1; i &lt; = number; i++) {\r\n\t\t\t\t\tboolean mod3 = i % 3 == 0;\r\n\t\t\t\t\tboolean mod5 = i % 5 == 0;\r\n\t\t\t\t\tif (mod5 &amp;&amp; mod3) {\r\n\t\t\t\t\t\tSystem.out.println(\"Hop\");\r\n\t\t\t\t\t} else if (mod3) {\r\n\t\t\t\t\t\tSystem.out.println(\"Hoppity\");\r\n\t\t\t\t\t} else if (mod5) {\r\n\t\t\t\t\t\tSystem.out.println(\"Hophop\");\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn;\r\n\t}\r\n}<\/pre>\n<p>Lo m\u00e1s complicado aqu\u00ed es asegurarnos que el n\u00famero pueda ser leido si tiene espacios. No hay otras restricciones aparentes.<\/p>\n<p>No muestro el wrapper ni el archivo de compilaci\u00f3n Ant ya<a href=\"http:\/\/kodegeek.com\/blog\/2009\/03\/02\/facebook-puzzless-i-meepmeep\/\" target=\"_self\"> que son muy parecidos al del problema anterior<\/a>.<\/p>\n<p>Veneblogs: <a rel=\"tag\" href=\"http:\/\/www.veneblogs.com\/etiquetas\/java\">java<\/a>, <a rel=\"tag\" href=\"http:\/\/www.veneblogs.com\/etiquetas\/facebook\">facebook<\/a>, <a rel=\"tag\" href=\"http:\/\/www.veneblogs.com\/etiquetas\/puzzles\">puzzles<\/a>, <a rel=\"tag\" href=\"http:\/\/www.veneblogs.com\/etiquetas\/meepmeep\">meepmeep<\/a><br \/>\nBlogalaxia: <a rel=\"tag\" href=\"http:\/\/www.blogalaxia.com\/tags\/java\">java<\/a>, <a rel=\"tag\" href=\"http:\/\/www.blogalaxia.com\/tags\/facebook\">facebook<\/a>, <a rel=\"tag\" href=\"http:\/\/www.blogalaxia.com\/tags\/puzzles\">puzzles<\/a>, <a rel=\"tag\" href=\"http:\/\/www.blogalaxia.com\/tags\/meepmeep\">meepmeep<\/a><\/p>\n<p>To2blogs: <a rel=\"tag\" href=\"http:\/\/www.to2blogs.com\/tag\/java\">java<\/a>, <a rel=\"tag\" href=\"http:\/\/www.to2blogs.com\/tag\/facebook\">facebook<\/a>, <a rel=\"tag\" href=\"http:\/\/www.to2blogs.com\/tag\/puzzles\">puzzles<\/a>, <a rel=\"tag\" href=\"http:\/\/www.to2blogs.com\/tag\/meepmeep\">meepmeep<\/a><\/p>\n<p>Technorati: <a rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/java\">java<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/facebook\">facebook<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/puzzles\">puzzles<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/meepmeep\">meepmeep<\/a><\/p>\n<p>Del.icio.us: <a rel=\"tag\" href=\"http:\/\/del.icio.us\/tag\/java\">java<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/tag\/facebook\">facebook<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/tag\/puzzles\">puzzles<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/tag\/meepmeep\">meepmeep<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un nuevo rompecabezas, un poco m\u00e1s complicado: package com.kodegeek.blog.jobsearch.facebook.hoppity; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; \/** * To help test whether your puzzle submissions fit the guidelines, try this simple test puzzle. * Your solution must follow the guidelines like any other puzzle. * Write a program that takes as input a single <a class=\"read-more\" href=\"http:\/\/kodegeek.com\/blog\/2009\/03\/03\/facebook-puzzles-ii-hoppity\/\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9,438],"tags":[236,485,482],"_links":{"self":[{"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/posts\/1651"}],"collection":[{"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/comments?post=1651"}],"version-history":[{"count":6,"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/posts\/1651\/revisions"}],"predecessor-version":[{"id":1658,"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/posts\/1651\/revisions\/1658"}],"wp:attachment":[{"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/media?parent=1651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/categories?post=1651"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/tags?post=1651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}