summaryrefslogtreecommitdiffstats
path: root/day8/day8-1.js
diff options
context:
space:
mode:
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)
+