我感到厭惡,我卡住了,我真的不能包住我的腦袋周圍什麼是錯的。問題讀取。項目歐拉在F#8#
查找1000位數字中具有最大產品的13個相鄰數字。這個產品的價值是什麼?
現在我將數字存儲爲一個字符串,我只取數字,循環並將每個13位數的「substring」作爲一個數組,並將它們相乘並進行比較。現在我已經驗證了我只能得到一個1000位數的char數組,我已經驗證了我得到了75個相同大小的char數組。但我沒有得到正確的答案。
下面是代碼
let problem8() =
let str = @"731671765313306..."
|> Seq.filter (Char.IsDigit)
|> Seq.toArray
(* We only need to go to 987 because 1000 isn't divisble by 13 and if we were to take the last 11 digits from 987
we would end up with 0 anyhow. *)
seq { for i in 0.. 13 ..987 -> str.[i..i + 12] }
|> Seq.map (Seq.fold (fun acc chr -> acc * int64 (Char.GetNumericValue(chr))) 1L)
|> Seq.max
problem8()
|> printfn "%d"
對於'123456'中的4位數字,您應該使用'3456',而不是使用'1234'停止。 – raina77ow 2014-11-22 21:51:21