Skip to content

Commit

Permalink
- rewrote execute with a while loop
Browse files Browse the repository at this point in the history
  • Loading branch information
theburningmonk committed Dec 27, 2016
1 parent 38f3e44 commit 1d00723
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/AdventOfCode2016/Day25_Part1_Part2.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,28 @@ let execute initValues (instructions : Instruction[]) =
match registers.TryGetValue reg with
| true, n -> n
| _ -> 0

let rec loop idx = seq {
if idx >= instructions.Length then ()
else
seq {
let mutable idx = 0
while idx < instructions.Length do
match instructions.[idx] with
| Cpy (n, Reg dest) ->
registers.[dest] <- fetch n
yield! loop (idx+1)
idx <- idx + 1
| Inc reg ->
registers.[reg] <- registers.[reg] + 1
yield! loop (idx+1)
idx <- idx + 1
| Dec reg ->
registers.[reg] <- registers.[reg] - 1
yield! loop (idx+1)
| Jnz (n, offset) when fetch n <> 0 ->
yield! loop (idx+fetch offset)
idx <- idx + 1
| Jnz (n, offset) when fetch n <> 0 ->
idx <- idx + fetch offset
| Out n ->
yield fetch n
yield! loop (idx+1)
idx <- idx + 1
| _ ->
yield! loop (idx+1)
idx <- idx + 1
}

loop 0

let part1 =
Seq.initInfinite id
Expand Down

0 comments on commit 1d00723

Please sign in to comment.