Skip to content

Commit

Permalink
Add day 6 part 1 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
harryagstian committed Dec 6, 2021
1 parent 2ada391 commit aceb569
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
output
output
node_modules
29 changes: 29 additions & 0 deletions js/day6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { readFromFile, printSolution } = require('./utility')
const flags = require('flags')

const solve = (sample) => {
const inputs = readFromFile(6, sample)

let arr = inputs.split(",").map(Number)
console.log(arr)
for (let i = 0; i < 256; i++) {
const len = arr.length
for (let j = 0; j < len; j++) {
let current = arr[j] - 1

if (current < 0) {
arr.push(8)
current = 6
}
arr[j] = current
}
}

printSolution(arr.length)
}

flags.defineBoolean("sample", false, "run with sample")
flags.defineBoolean("s", false, "run with sample")
flags.parse()

solve(flags.get("sample") || flags.get("s"))
1 change: 1 addition & 0 deletions js/inputs/day6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2,4,1,5,1,3,1,1,5,2,2,5,4,2,1,2,5,3,2,4,1,3,5,3,1,3,1,3,5,4,1,1,1,1,5,1,2,5,5,5,2,3,4,1,1,1,2,1,4,1,3,2,1,4,3,1,4,1,5,4,5,1,4,1,2,2,3,1,1,1,2,5,1,1,1,2,1,1,2,2,1,4,3,3,1,1,1,2,1,2,5,4,1,4,3,1,5,5,1,3,1,5,1,5,2,4,5,1,2,1,1,5,4,1,1,4,5,3,1,4,5,1,3,2,2,1,1,1,4,5,2,2,5,1,4,5,2,1,1,5,3,1,1,1,3,1,2,3,3,1,4,3,1,2,3,1,4,2,1,2,5,4,2,5,4,1,1,2,1,2,4,3,3,1,1,5,1,1,1,1,1,3,1,4,1,4,1,2,3,5,1,2,5,4,5,4,1,3,1,4,3,1,2,2,2,1,5,1,1,1,3,2,1,3,5,2,1,1,4,4,3,5,3,5,1,4,3,1,3,5,1,3,4,1,2,5,2,1,5,4,3,4,1,3,3,5,1,1,3,5,3,3,4,3,5,5,1,4,1,1,3,5,5,1,5,4,4,1,3,1,1,1,1,3,2,1,2,3,1,5,1,1,1,4,3,1,1,1,1,1,1,1,1,1,2,1,1,2,5,3
1 change: 1 addition & 0 deletions js/inputs/day6sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3,4,3,1,2
2 changes: 1 addition & 1 deletion js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions js/template.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const { readFromFile, printSolution } = require('./utility')
const flags = require('flags')

const solve = () => {
const solve = (sample) => {
const inputs = readFromFile(4, sample)
printSolution(inputs)
}

flags.defineBoolean("sample", false, "run with sample")
flags.defineBoolean("s", false, "run with sample")
flags.parse()

solve(flags.get("sample"))
solve(flags.get("sample") || flags.get("s"))

0 comments on commit aceb569

Please sign in to comment.