summaryrefslogtreecommitdiffstats
path: root/day8/day8-1.js
diff options
context:
space:
mode:
authorGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-10 20:24:16 +0100
committerGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-10 20:24:16 +0100
commitb50c9c40ae474cd0e4eb543504e47dc6dbea31e9 (patch)
tree9e03fce1d603e013847c5fbea780dd0bd2a62a47 /day8/day8-1.js
parentc0617b6edbae172752b58276a7678e8c97ade3e7 (diff)
downloadadvent_of_code_2020-b50c9c40ae474cd0e4eb543504e47dc6dbea31e9.tar.gz
advent_of_code_2020-b50c9c40ae474cd0e4eb543504e47dc6dbea31e9.tar.bz2
advent_of_code_2020-b50c9c40ae474cd0e4eb543504e47dc6dbea31e9.zip
day8
Diffstat (limited to 'day8/day8-1.js')
-rw-r--r--day8/day8-1.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/day8/day8-1.js b/day8/day8-1.js
new file mode 100644
index 0000000..12f0e4a
--- /dev/null
+++ b/day8/day8-1.js
@@ -0,0 +1,28 @@
+const data = require('./data')
+const splitted = data
+ .map(s => s.split(' '))
+ .map(s => [s[0], parseInt(s[1])])
+
+let cont = true, field = 0, accu=0
+while (cont && !splitted[field][2]) {
+ switch(splitted[field][0]) {
+ case 'nop':
+ splitted[field].push(true)
+ field += 1
+ break
+ case 'acc':
+ splitted[field].push(true)
+ accu += splitted[field][1]
+ field += 1
+ break
+ case 'jmp':
+ splitted[field].push(true)
+ field += splitted[field][1]
+ break;
+ default:
+ cont = false
+ }
+}
+
+console.log(accu)
+