New answers tagged

1

A Map would have a roughly constant time lookup on keys but if there only going to be 4 entries then checking each item in an array will probably be quicker anyway. I think a much bigger issue is the repetition in the code and use of a ResizeArray to write in an imperative style when that can be easily avoided. Both of those issues are covered in this ...


1

A first simple clean up could be made here: | 1 -> let a = ops.[ops.[i+1]] let b = ops.[ops.[i+2]] ops.[ops.[i+3]] <- a + b i <- i + 4 | 2 -> let a = ops.[ops.[i+1]] let b = ops.[ops.[i+2]] ops.[ops.[i+3]] <- a * b i <- i + 4 The ...


4

Possibly not the best solution, but here's one that uses F# more extensively: let rec processProgram (i: int) (ops: int list) = match ops with | opCode :: aPos :: bPos :: outPos :: rest when opCode = 1 -> // add op code let a = ops |> List.item aPos let b = ops |> List.item bPos let complete = [opCode; aPos; bPos; ...


Top 50 recent answers are included