this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Day 4 done. Will fill in backlog sooooon

Seth Etter 3230ec0a

+66
+1
.gitignore
··· 1 + node_modules
+13
index.js
··· 1 + var fs = require('fs'); 2 + 3 + // TODO: Go back and redo days 1 - 3, for consistency :) 4 + 5 + /** 6 + * Day 4! 7 + * ---------------------------------- 8 + */ 9 + var day4Input = fs.readFileSync('./input/day4.txt', 'utf8').replace(/[^A-z0-9]/g, ''); 10 + var day4Part1Answer = require('./lib/day4').getTheAnswer(day4Input, '00000'); 11 + var day4Part2Answer = require('./lib/day4').getTheAnswer(day4Input, '000000'); 12 + console.log('Day 4, Part 1: ', day4Part1Answer); 13 + console.log('Day 4, Part 2: ', day4Part2Answer);
+1
input/day4.txt
··· 1 + yzbqklnj
+17
lib/day4.js
··· 1 + var crypto = require('crypto'); 2 + var fs = require('fs'); 3 + 4 + module.exports = { 5 + getTheAnswer: function(input, frontPadding) { 6 + var hash = '', 7 + answer = -1; 8 + 9 + while (hash.substring(0, frontPadding.length) !== frontPadding) { 10 + hash = crypto.createHash('md5').update(input + (++answer)).digest('hex'); 11 + } 12 + 13 + return answer; 14 + } 15 + }; 16 + 17 +
+25
package.json
··· 1 + { 2 + "name": "advent-of-code", 3 + "version": "1.0.0", 4 + "description": "Advent Of Code solutions in JS.", 5 + "main": "index.js", 6 + "scripts": { 7 + "start": "node index.js", 8 + "test": "./node_modules/.bin/mocha spec" 9 + }, 10 + "repository": { 11 + "type": "git", 12 + "url": "git+ssh://git@github.com/sethetter/advent-of-code.git" 13 + }, 14 + "author": "Seth Etter <sethetter@gmail.com> (http://sethetter.com)", 15 + "license": "ISC", 16 + "bugs": { 17 + "url": "https://github.com/sethetter/advent-of-code/issues" 18 + }, 19 + "homepage": "https://github.com/sethetter/advent-of-code#readme", 20 + "devDependencies": {}, 21 + "dependencies": { 22 + "chai": "^3.4.1", 23 + "mocha": "^2.3.4" 24 + } 25 + }
+9
spec/day4.spec.js
··· 1 + var expect = require('chai').expect; 2 + 3 + var Day4 = require('../lib/day4'); 4 + 5 + describe('getTheAnswer', function() { 6 + it('returns the correct answer', function() { 7 + expect(Day4.getTheAnswer('abcdef', '00000')).to.equal(609043); 8 + }); 9 + });