|
|
@@ -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)
|