summary refs log tree commit diff stats
path: root/day17.fsx
diff options
context:
space:
mode:
Diffstat (limited to 'day17.fsx')
-rw-r--r--day17.fsx27
1 files changed, 27 insertions, 0 deletions
diff --git a/day17.fsx b/day17.fsx
new file mode 100644
index 0000000..33bf215
--- /dev/null
+++ b/day17.fsx
@@ -0,0 +1,27 @@
+type CircularArray =
+    struct
+        val mutable arr: int array
+        val mutable position: int
+        val mutable stepNum: int
+        val increment: int
+        new(i) = {arr=[|0|]; position=0; stepNum=1; increment=i}
+
+        member this.step() = 
+            this.position <- 1 + (this.position + this.increment) % (Array.length this.arr)
+            this.arr <- Array.insertAt this.position this.stepNum this.arr
+            this.stepNum <- this.stepNum + 1
+    end
+
+let () =
+    let mutable arr = new CircularArray(377)
+    for i = 1 to 2017 do
+        arr.step()
+        
+    arr.arr[arr.position+1] |> printfn "%d"
+    
+    let mutable p = 0
+    let mutable oneth = 1
+    for i = 1 to 50000000 do
+        p <- (p + (377 % i) + 1) % i
+        if p = 0 then oneth <- i
+    printfn "%d" oneth
\ No newline at end of file