【发布时间】:2015-01-23 00:50:55
【问题描述】:
我正在从事 Project Euler,我在 problem 8,我正在尝试一个简单的蛮力:将数字的每个连续 5 位相乘,用结果列出一个列表,然后找到更高的。
这是我目前尝试用 J 编写的代码:
n =: 731671765313x
NB. 'n' will be the complete 1000-digits number
itl =: (".@;"0@":)
NB. 'itl' transform an integer in a list of his digit
N =: itl n
NB. just for short writing
takeFive =: 5 {. ] }.~ 1 -~ [
NB. this is a dyad, I get this code thanks to '13 : '5{.(x-1)}.y'
NB. that take a starting index and it's applied to a list
如何将 takeFive 用于 N 的所有索引? 我试过了:
(i.#N) takeFive N
|length error: takeFive
| (i.#N) takeFive N
但它不起作用,我不知道为什么。 谢谢大家。
【问题讨论】:
-
请注意:您的
itl可以简单地使用 Base (#.)N =: 10 #.inv n987654325@的倒数替换
标签: loops j tacit-programming