Created
December 3, 2020 11:12
-
-
Save object/bcc9ed734961d438ba0b3ce6b39a717d to your computer and use it in GitHub Desktop.
AdventOfCode 2020, December 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| open System | |
| open System.IO | |
| let area = | |
| File.ReadAllLines("input03.txt") | |
| |> Array.filter (not << String.IsNullOrEmpty) | |
| |> Array.map Seq.toArray | |
| |> Array.map (fun line -> line |> Array.map (fun x -> if x = '#' then 1 else 0)) | |
| let rec go steps (area : (int array) array) current_pos count = | |
| let (x,y) = current_pos | |
| if y + 1 = area.Length then | |
| count | |
| else | |
| let x = x + (fst steps) | |
| let y = y + (snd steps) | |
| let row = area.[y] | |
| let count = count + row.[x % row.Length] | |
| go steps area (x,y) count | |
| [ | |
| (1,1) | |
| (3,1) | |
| (5,1) | |
| (7,1) | |
| (1,2) | |
| ] | |
| |> List.map (fun steps -> go steps area (0,0) 0) | |
| |> List.map int64 | |
| |> List.reduce (*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment