{"id":606,"date":"2012-08-08T17:20:02","date_gmt":"2012-08-08T21:20:02","guid":{"rendered":"http:\/\/www.joshho.com\/blog\/?p=606"},"modified":"2017-08-01T15:58:32","modified_gmt":"2017-08-01T19:58:32","slug":"project-euler-problem-52","status":"publish","type":"post","link":"https:\/\/www.joshho.com\/blog\/2012\/08\/08\/project-euler-problem-52\/","title":{"rendered":"Project Euler &#8211; Problem 52"},"content":{"rendered":"<p>Problem 52:<br \/>\nIt can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.<\/p>\n<p>Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.<br \/>\n<!--more--><br \/>\n<code><\/p>\n<pre lang='java'>\r\nclass runner\r\n{\t\r\n\tpublic static boolean matchCharacters(String x, String y){\r\n\t\tif(x.length() != y.length()) return false;\r\n\t\tboolean[] y1 = new boolean[x.length()];\r\n\t\t\r\n\t\tfor(int i=0;i<y1.length;i++){\r\n\t\t\tboolean found = false;\r\n\t\t\tfor(int j=0;j<y1.length; j++){\r\n\t\t\t\tif(!y1[j] &#038;&#038; x.charAt(i) == y.charAt(j)){\r\n\t\t\t\t\tfound = true;\r\n\t\t\t\t\ty1[j] = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(!found) return false;\r\n\t\t}\r\n\t\t\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic static void main (String[] args) throws java.lang.Exception\r\n\t{\r\n\t\tlong time = System.currentTimeMillis();\r\n\r\n\t\tint n=2;\r\n\t\twhile(true){\r\n\t\t\tString str_n = \"\"+n;\r\n\t\t\tboolean found = true;\r\n\t\t\tfor(int i=2;i<7;i++){\r\n\t\t\t\tif(!matchCharacters(str_n, \"\"+(i*n))){\r\n\t\t\t\t\tfound = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(found) break;\r\n\t\t\tn++;\r\n\t\t}\r\n\t\tSystem.out.println(\"n:\"+n);\r\n\t\tSystem.out.println(\"time: \"+(System.currentTimeMillis() - time));\r\n\t}\r\n}\r\n<\/pre>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem 52:<br \/>\nIt can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.<\/p>\n<p>Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56],"tags":[],"class_list":["post-606","post","type-post","status-publish","format-standard","hentry","category-project-euler"],"_links":{"self":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/comments?post=606"}],"version-history":[{"count":5,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/606\/revisions"}],"predecessor-version":[{"id":967,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/606\/revisions\/967"}],"wp:attachment":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/media?parent=606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/categories?post=606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/tags?post=606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}