NB. Martin Gardner II NB. fibonacci number NB. Usage: fib 10 fib=: 3 : ' {: (] ,[: +/ _2&{.)^:(i.y) 1 1' NB. fibonatti base of D.Knuth NB. base using fibonacci numbers fib_sub=: 3 : '(}.(fib 12) < y)# }.fib 12' fib_base=: 3 : 0 fib0=: |. fib_sub y base0=: ({. fib0),(<: # fib0)#0 ) fib_all=: 3 : 0 NB. u 19 tmp1=. (#:i.1024) # }. tmp0=: fib 10 ind0=. (+/"1 tmp1) e. y ind1=. |."1 ind0 # tmp1 tmp2,(tmp2=.|.}. tmp0) e."1 ind1 ) NB. -------------------------------------- NB. GardnerII no 3 -7 NB. Dudeney question NB. a b c * d e = f g * h i NB. common utilities tap=: i.@! A. i. NB. Table of all permutations ts=: 6!:2 , 7!:2@] NB. Time and space NB. ----------------------------------- NB. common script numerical_sub=: 4 : 0 NB. x is 3 or 2 NB. y is table_123_sub '' NB. same 10 #. 1 2 3 /is base 10 NB. 10 #. 1 2 3 using lot of memory and may hang-up if. 3 = x do. +/ (L:0) 100 10 1 * L:0 y else. +/ (L:0) 10 1 * L:0 y end. ) NB.---------------------------------- NB. 1. using matrices method and calc once calc_tab=: 3 : 0 NB. main // Usage: calc_tab '' ind =. =/"1 calc_ans_sub tmp0=. tab_all '' NB. find abc*de = fg*hi tmp2=. ind # tmp0 NB. copy/pickup answer tmp2 ,. {calc_ans_sub tmp2 NB. form for output ) tab_all=: 3 : 0 NB. compose all combination table tmp=.|: >{ L:0 |:(L:0) 1 0 0 1 0 1 0 1 0 <;.1 |: >: tap 9 (3 numerical_sub {."1 tmp),. 2 numerical_sub }."1 tmp NB. {. is head and }. is drop head ) NB. format for ans calc_ans_sub=: 3 : '(*/"1 ;("1) 0 1{"1 y),.*/"1 ;("1) 2 3{"1 y' NB. ---------------------------------------- NB. ---------------------------------------- NB. 2. Loop method calc_loop_main=: 3 : 0 NB. Usage: calc_loop_main '' Mabc =. 10 #. L:0 , table_abc_sub '' NB. 9 * 56 Mde=. , table_de_sub&table_abc_sub '' NB. 9 * 56 ANS=.<'' for_ctr0. i. # Mabc do. NB.ctr0= 504 TMabc=. ctr0{Mabc TMd2i=. table_d2i_sub ctr0{Mde NB. 720*56=40320 for_ctr1. i.# TMd2i do. NB. ctr1=40320 tmp=. 10 #. (L:0) 1 0 1 0 1 0 <;.1 > ctr1{TMd2i tmp=. TMabc,tmp ind=. (tmp3=. */ > 0 1 { tmp) = tmp4=. */ >2 3 { tmp if. 1=ind do. ANS=. ANS, ,.}.ANS ) table_abc_sub=: 3 : 0 NB. u '' NB. n=9*8*7=504 NR9=. >:i.9 tab_0=. > { L:0({@> NR9),. L:0 NR9 -. (L:0){@> NR9 tmp0=. NR9 -. L:0 tab_0 tmp1=. |: (L:0) 7# "0 (L:0) tab_0 ,.> { L:0 tmp1,. L:0 tmp0 ) table_de_sub=: 3 : ' (>: i.9) -. L:0 y' table_de_all=: table_de_sub&table_abc_sub table_d2i_sub=: 3 : '|: >{ L:0 (tap 6) { L:0 y'