Bläddra i källkod

Add the part two for each adventofcode problem

Matt Coles 9 år sedan
förälder
incheckning
2dec3897fb
2 ändrade filer med 42 tillägg och 0 borttagningar
  1. 13 0
      adventofcode/advent01-2.mc
  2. 29 0
      adventofcode/advent02-2.mc

+ 13 - 0
adventofcode/advent01-2.mc

@@ -0,0 +1,13 @@
1
+; Requires the input for Advent of Code(http://adventofcode.com/) Day 1
2
+(include str fs maths)
3
+(assign input (fs::readIn "advent.txt"))
4
+(assign i 0)
5
+(assign result 0)
6
+(repeat (str::length input)
7
+  (assign current (str::charAtIndex input i))
8
+  (if (eq result "-1") (log i))
9
+  (if (eq current "(") (assign result (maths::add result 1)))
10
+  (if (eq current ")") (assign result (maths::subtract result 1)))
11
+  (assign i (maths::add i 1))
12
+)
13
+(log result)

+ 29 - 0
adventofcode/advent02-2.mc

@@ -0,0 +1,29 @@
1
+; Requires the input for Advent of Code(http://adventofcode.com/) Day 2
2
+(include str fs maths)
3
+(assign input (fs::readIn "advent.txt"))
4
+(assign i 0)
5
+(assign resultone "")
6
+(assign resulttwo "")
7
+(assign resultthree "")
8
+(assign result 0)
9
+(assign currNum 1)
10
+(repeat (str::length input)
11
+  (assign current (str::charAtIndex input i))
12
+  (if (eq current "x") 
13
+    (assign currNum (maths::add currNum 1)) |
14
+    (if (eq current "\n") 
15
+      (assign currNum 1) 
16
+      (assign result (maths::add (maths::add 
17
+                     (maths::min (maths::add (maths::multiply 2 resultone) (maths::multiply 2 resulttwo)) (maths::add (maths::multiply 2 resulttwo) (maths::multiply 2 resultthree)) (maths::add (maths::multiply 2 resultthree) (maths::multiply 2 resultone))) 
18
+                     (maths::multiply resultone (maths::multiply resulttwo resultthree))) result))
19
+      (assign resultone "")
20
+      (assign resulttwo "")
21
+      (assign resultthree "") | 
22
+        (if (eq currNum 1) (assign resultone (str::concat resultone current)))
23
+        (if (eq currNum 2) (assign resulttwo (str::concat resulttwo current))) 
24
+        (if (eq currNum 3) (assign resultthree (str::concat resultthree current)))
25
+    )
26
+  )
27
+  (assign i (maths::add i 1))
28
+)
29
+(log result)