From 767c8d9bea824b05fd24549e7dce6c738c90aaab Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Mon, 27 Jun 2022 20:15:32 +0200 Subject: Problem 51 --- problem51.ijs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 problem51.ijs 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 -- cgit v1.2.3