-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday11_part02.fs
50 lines (38 loc) · 2.1 KB
/
day11_part02.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module day11_part02
open AoC_2019.Modules
open System.Collections.Generic
let paintingMap = createPanel(200, 1)
let paintedPositionMap = new Dictionary<(int * int), int>()
let rec getNextPaintPosition(values: Dictionary<bigint, bigint>, relativeBase: bigint, currentDirection: DirectionEnum, position:int[], inputColor:bigint, idx:bigint, paintedCount: int) =
// GET COLOR
let colorResult = IntCodeModule.getOutput values idx relativeBase [inputColor] true 0I
// GET DIRECTION
let directionResult = IntCodeModule.getOutput values colorResult.Idx colorResult.RelativeBase [0I] true 0I
// SET COLOR
paintingMap.[(position.[0], position.[1])] <- (int)colorResult.Output
let alreadyPainted, value = paintedPositionMap.TryGetValue ((position.[0], position.[1]))
match alreadyPainted with
| false -> paintedPositionMap.Add((position.[0], position.[1]), (int)colorResult.Output)
| _ -> ()
// SET DIRECTION
let (nextDirection, nextCoord) =
match (currentDirection, (int)directionResult.Output) with
| (UP, 0) -> getNextPosition(LEFT, position)
| (UP, 1) -> getNextPosition(RIGHT, position)
| (DOWN, 0) -> getNextPosition(RIGHT, position)
| (DOWN, 1) -> getNextPosition(LEFT, position)
| (LEFT, 0) -> getNextPosition(DOWN, position)
| (LEFT, 1) -> getNextPosition(UP, position)
| (RIGHT, 0) -> getNextPosition(UP, position)
| (RIGHT, 1) -> getNextPosition(DOWN, position)
| (_, _) -> (currentDirection, position)
let nextColor = bigint paintingMap.[(nextCoord.[0], nextCoord.[1])]
match colorResult.Continue with
| true -> getNextPaintPosition(values, directionResult.RelativeBase, nextDirection, nextCoord, nextColor, directionResult.Idx, paintedCount + 1 )
| false -> paintedPositionMap.Keys.Count
let execute =
let filepath = __SOURCE_DIRECTORY__ + @"../../day11_input.txt"
let initialPoint=[|0;0|]
let values = IntcodeComputerModule.getInputBigData filepath
let paintedPositions = getNextPaintPosition(values, 0I, UP, initialPoint, 1I, 0I, 0)
printPanel(paintingMap, 50, 10)