为了学习F#我正试图解决Codingame之谜下降
下面的代码适用于第一次运行,但似乎在第一次循环后为不同的输入提供完全相同的结果.
使用数组在Interactive中运行idxWithHighestValue函数而不是从控制台读取会产生所需的结果.
预期行为:
[9,8,7,6,5,4,3,2] => 0
[0,8,7,6,5,4,3,2] => 1
实际行为:
[9,8,7,6,5,4,3,2] => 0
[0,8,7,6,5,4,3,2] => 0
open System
let highestMountain =
let readEightInputs =
let readlines n = Array.init n (fun _ -> Console.In.ReadLine() |> int)
readlines 8
let idxWithHighestValue list =
list
|> Seq.mapi (fun i v -> i, v)
|> Seq.maxBy snd
|> fst
idxWithHighestValue readEightInputs
(* game loop *)
while true do
(* Write an action using printfn *)
(* To debug: …Run Code Online (Sandbox Code Playgroud) f# ×2