i'm working on project euler, i'm on problem 8, , i'm trying simple brute force: multiply each consecutive 5 digit of number, make list results, , find higher.
this code i'm trying write in j:
n =: 731671765313x nb. 'n' complete 1000-digits number itl =: (".@;"0@":) nb. 'itl' transform integer in list of digit n =: itl n nb. short writing takefive =: 5 {. ] }.~ 1 -~ [ nb. dyad, code '13 : '5{.(x-1)}.y' nb. take starting index , it's applied list how can use takefive index of n? tried:
(i.#n) takefive n |length error: takefive | (i.#n) takefive n but doesn't work , don't know why. thank all.
1. reason (i.#n) takefive n not working trying run 5{. ((i.#n)-1) }. nbut have use x not list atom. can setting appropriate left-right rank " of verb:
(i.#n) (takefive"0 _) n 7 3 1 6 7 7 3 1 6 7 3 1 6 7 1 1 6 7 1 7 6 7 1 7 6 7 1 7 6 5 1 7 6 5 3 7 6 5 3 1 6 5 3 1 3 5 3 1 3 0 3 1 3 0 0 1 3 0 0 0 2. 1 other way bind (&) list (n) takefive , run binded-verb through every i.#n. this, it's better use reverse version of takefive: takefive~:
((n&(takefive~))"0) i.#n 7 3 1 6 7 7 3 1 6 7 3 1 6 7 1 1 6 7 1 7 6 7 1 7 6 7 1 7 6 5 1 7 6 5 3 7 6 5 3 1 6 5 3 1 3 5 3 1 3 0 3 1 3 0 0 1 3 0 0 0 or (n&(takefive~)) each i.#n.
3. think, though, infix dyad \ might serve better:
5 >\n 7 3 1 6 7 3 1 6 7 1 1 6 7 1 7 6 7 1 7 6 7 1 7 6 5 1 7 6 5 3 7 6 5 3 1 6 5 3 1 3
Comments
Post a Comment