Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 572d6bc

Browse filesBrowse files
refactor(2020-day-02): initialize for 2020 day 02
1 parent 5c3f908 commit 572d6bc
Copy full SHA for 572d6bc

File tree

Expand file treeCollapse file tree

3 files changed

+36
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+36
-0
lines changed

‎2020/day-02/index.js

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./solution')

‎2020/day-02/input.txt

Copy file name to clipboardExpand all lines: 2020/day-02/input.txt
Whitespace-only changes.

‎2020/day-02/solution.js

Copy file name to clipboard
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const filePath = path.join(__dirname, 'input.txt')
4+
const { inputToArray } = require('../../2018/inputParser')
5+
6+
fs.readFile(filePath, { encoding: 'utf8' }, (err, initData) => {
7+
if (err) throw err
8+
9+
initData = inputToArray(initData.trim())
10+
11+
const resetInput = () => {
12+
// Deep copy to ensure we aren't mutating the original data
13+
return JSON.parse(JSON.stringify(initData))
14+
}
15+
16+
const part1 = () => {
17+
const data = resetInput()
18+
console.debug(data)
19+
return 'No answer yet'
20+
}
21+
22+
const part2 = () => {
23+
const data = resetInput()
24+
console.debug(data)
25+
return 'No answer yet'
26+
}
27+
const answers = []
28+
answers.push(part1())
29+
answers.push(part2())
30+
31+
answers.forEach((ans, idx) => {
32+
console.info(`-- Part ${idx + 1} --`)
33+
console.info(`Answer: ${ans}`)
34+
})
35+
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.