-
Notifications
You must be signed in to change notification settings - Fork 0
/
day9.coffee
41 lines (36 loc) · 997 Bytes
/
day9.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
_ = require( 'lodash' )
aoc = require( './aoc_util' )
data = require( './data/day9' )
#data = aoc.parseArray( data, '\n' )
#data = aoc.parseIntArray( data, '\t' )
#data = aoc.parseFloatArray( data, '\n' )
#data = aoc.parse2DIntArray( data, '\t' )
#data = aoc.parse2DIntArray( data, '\t' )
#data = aoc.parse2DIntArray( data, '\t' )
#data = "<{o\"i!a,<{i<a>"
x = 0
garbage = false
currentGroupValue = 0
totalGroupsValue = 0
garbageCount = 0
while x < data.length
switch data.charAt(x)
when '{'
currentGroupValue++ unless garbage
garbageCount++ if garbage
when '}'
totalGroupsValue += currentGroupValue unless garbage
currentGroupValue-- unless garbage
garbageCount++ if garbage
when '<'
garbageCount++ if garbage
garbage = true unless garbage
when '>'
garbage = false
when '!'
x++
else
garbageCount++ if garbage
x++
console.log "Group values: " + totalGroupsValue
console.log "Garbage: " + garbageCount