|
|
@@ -0,0 +1,27 @@
|
|
|
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 (add currNum 1)) |
|
|
|
14
|
+ (if (eq current "\n")
|
|
|
15
|
+ (assign currNum 1)
|
|
|
16
|
+ (assign result (add result (add (add (multiply 2 (multiply resultone resulttwo)) (add (multiply 2 (multiply resulttwo resultthree)) (multiply 2 (multiply resultone resultthree)))) (maths::min (multiply resultone resulttwo) (multiply resulttwo resultthree) (multiply resultthree resultone)))))
|
|
|
17
|
+ (assign resultone "")
|
|
|
18
|
+ (assign resulttwo "")
|
|
|
19
|
+ (assign resultthree "") |
|
|
|
20
|
+ (if (eq currNum 1) (assign resultone (str::concat resultone current)))
|
|
|
21
|
+ (if (eq currNum 2) (assign resulttwo (str::concat resulttwo current)))
|
|
|
22
|
+ (if (eq currNum 3) (assign resultthree (str::concat resultthree current)))
|
|
|
23
|
+ )
|
|
|
24
|
+ )
|
|
|
25
|
+ (assign i (add i 1))
|
|
|
26
|
+)
|
|
|
27
|
+(log result)
|