我感到厌恶,我卡住了,我真的不能包住我的脑袋周围什么是错的。问题读取。项目欧拉在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