Skip to content

Commit 131652c

Browse files
feat(2020-day-04): count all passports that have all fields valid
Solution for part 2
1 parent cfe1725 commit 131652c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

2020/day-04/solution.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ const { parseScan, validate } = require('./passports')
77

88
const answers = []
99

10-
const part1 = () => {
10+
const scanPassports = () => {
1111
let recordBuffer = ''
1212
let validCount = 0
13+
let validWithFieldsCount = 0
1314
let invalidCount = 0
1415
let totalCount = 0
1516

@@ -20,6 +21,9 @@ const part1 = () => {
2021
if (validate(passport, false)) {
2122
validCount++
2223
}
24+
if (validate(passport)) {
25+
validWithFieldsCount++
26+
}
2327
} catch (e) {
2428
invalidCount++
2529
if (DEBUG) {
@@ -49,7 +53,7 @@ const part1 = () => {
4953
console.info('Total passports found:', totalCount)
5054
console.info('Invalid passports', invalidCount)
5155
answers.push(validCount)
52-
answers.push(part2())
56+
answers.push(validWithFieldsCount)
5357

5458
answers.forEach((ans, idx) => {
5559
console.info(`-- Part ${idx + 1} --`)
@@ -61,8 +65,4 @@ const part1 = () => {
6165
return validCount
6266
}
6367

64-
const part2 = () => {
65-
return 'No answer yet'
66-
}
67-
68-
part1()
68+
scanPassports()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy