{"id":548,"date":"2012-08-05T02:35:14","date_gmt":"2012-08-05T06:35:14","guid":{"rendered":"http:\/\/www.joshho.com\/blog\/?p=548"},"modified":"2012-09-07T16:12:10","modified_gmt":"2012-09-07T20:12:10","slug":"project-euler-problem-38","status":"publish","type":"post","link":"https:\/\/www.joshho.com\/blog\/2012\/08\/05\/project-euler-problem-38\/","title":{"rendered":"Project Euler &#8211; Problem 38"},"content":{"rendered":"<p>Problem 38: Given the following example:<br \/>\n<center><\/p>\n<pre>192 x 1 = 192\r\n192 x 2 = 384\r\n192 x 3 = 576<\/pre>\n<p><\/center><br \/>\nBy concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)<\/p>\n<p>What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, &#8230; , n) where n &gt; 1?<br \/>\n<!--more--><br \/>\n<code><\/p>\n<pre lang='java'>\r\nclass runner\r\n{\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 limit = 1000000;\t\t\r\n\t\tfor(int n=1;n<limit;n++){\r\n\t\t\tboolean[] arr = new boolean[10];\/\/1-9 (we'll just ignore 0...)\t\t\t\r\n\t\t\tint i=1;\r\n\t\t\tString result = \"\";\r\n\t\t\t\r\n\t\t\tboolean pandigital = true;\r\n\t\t\touterLoop:\r\n\t\t\twhile(result.length() < 9){\r\n\t\t\t\tint o=n*i;\r\n\t\t\t\tint m=o; \r\n\t\t\t\twhile(m > 0){\r\n\t\t\t\t\tint r = m%10;\r\n\t\t\t\t\tif(r == 0){\r\n\t\t\t\t\t\tbreak outerLoop;\/\/Pandigital 1..9 doesn't contain 0.\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if(arr[r]){\r\n\t\t\t\t\t\tbreak outerLoop;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse arr[r] = true;\r\n\t\t\t\t\tm\/=10;\r\n\t\t\t\t}\r\n\t\t\t\tresult += o;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif(result.length() != 9) continue;\r\n\t\t\t\r\n\t\t\tfor(int j=1;j<arr.length;j++){\r\n\t\t\t\tif(!arr[j]) {pandigital = false; break;}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif(pandigital){\r\n\t\t\t\tSystem.out.println(n + \" 1..\"+(i-1)+\" concat:\"+result);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\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 38: Given the following example:<br \/>\n<center><\/p>\n<pre>192 x 1 = 192\r\n192 x 2 = 384\r\n192 x 3 = 576<\/pre>\n<p><\/center><br \/>\nBy concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)<\/p>\n<p>What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, &#8230; , n) where n &gt; 1?<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[56],"tags":[],"_links":{"self":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/548"}],"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=548"}],"version-history":[{"count":0,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/548\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/media?parent=548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/categories?post=548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/tags?post=548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}