summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--problem51.ijs36
1 files changed, 36 insertions, 0 deletions
diff --git a/problem51.ijs b/problem51.ijs
new file mode 100644
index 0000000..642eb64
--- /dev/null
+++ b/problem51.ijs
@@ -0,0 +1,36 @@
+group =: {{
+ 'low high' =. p:^:_1]10^y-1 0
+ p:low}.i.high
+}}
+
+patterns =: {{
+ I.(#~x=+/"1)#:i.2^y
+}}
+
+modified =: {{
+ (x patterns #y) {{10#.(i.10)(x})"0 1 y}}"1 y
+}}
+
+familysize =: {{
+ x {{
+ >./+/"1(1&p:*.(10^_1+#y)&<:)x modified y
+ }}"0 1] 10#.^:_1 y
+}}
+
+hasfamily =: {{
+ primes =. group y
+ sizes =. (1+i.y) familysize"0 1 primes
+ {.primes{~/:~(#~0<]),I.x<:sizes
+}}
+
+smallest =: {{
+ digits =. 10&#.^:_1]y
+ min =. 10^_1+#digits
+ groupsize =. 1+{.I.x=(1+i.#digits) familysize y
+ mods =. groupsize modified digits
+ {.(#~min&<:),mods#~x=+/"1(1&p:*.min&<:)mods
+}}
+
+find =: [ smallest hasfamily
+
+problem51 =: 8 find 6 NB. I know it is a 6 digit number :D \ No newline at end of file