我正在使用歐拉項目,我在problem 8上,我嘗試了一個簡單的蠻力:將每個連續的5位數字相乘,用結果列出一個清單,並找到更高的清單。默認函數將列表中的五個連續數字相乘:J,j701
這是我目前正試圖以J寫代碼:
n =: 731671765313x
NB. 'n' will be the complete 1000-digits number
itl =: ("[email protected];"[email protected]":)
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'可以用一個簡單的使用基地的倒數(#替換。)'N =:10#.inv n' – Dane