3b complete
This commit is contained in:
parent
047ecbd685
commit
3acbec3d91
2 changed files with 37 additions and 8 deletions
28
3/index.js
28
3/index.js
|
|
@ -1,17 +1,29 @@
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const regEx = /mul\(\d+,\d+\)/g
|
const regEx = /mul\(\d+,\d+\)|do\(\)|don\'t\(\)/g
|
||||||
let total = 0
|
let total = 0
|
||||||
|
let count = true
|
||||||
const input = fs.readFileSync("input.txt","utf-8")
|
const input = fs.readFileSync("input.txt","utf-8")
|
||||||
const result = input.match(regEx)
|
const result = input.match(regEx)
|
||||||
// console.log("hello world")
|
// console.log("hello world")
|
||||||
console.log(result)
|
console.log(result)
|
||||||
result.forEach((mulString)=>{
|
result.forEach((mulString)=>{
|
||||||
const numRegex= /\d+/g
|
if (mulString=="do()"){
|
||||||
const numbers = mulString.match(numRegex)
|
count=true
|
||||||
console.log(...numbers)
|
return
|
||||||
const aVal =parseInt(numbers[0])
|
}
|
||||||
const bVal=parseInt(numbers[1])
|
if(mulString=="don't()"){
|
||||||
total += aVal*bVal
|
count=false
|
||||||
})
|
return
|
||||||
|
}
|
||||||
|
if(count){
|
||||||
|
const numRegex= /\d+/g
|
||||||
|
const numbers = mulString.match(numRegex)
|
||||||
|
// console.log(...numbers)
|
||||||
|
const aVal =parseInt(numbers[0])
|
||||||
|
const bVal=parseInt(numbers[1])
|
||||||
|
total += aVal*bVal
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// console.log(dontLocations.length)
|
||||||
console.log("total: ",total)
|
console.log("total: ",total)
|
||||||
17
3/index3a.js
Normal file
17
3/index3a.js
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
const fs = require("fs")
|
||||||
|
const regEx = /mul\(\d+,\d+\)/g
|
||||||
|
let total = 0
|
||||||
|
const input = fs.readFileSync("input.txt","utf-8")
|
||||||
|
const result = input.match(regEx)
|
||||||
|
// console.log("hello world")
|
||||||
|
console.log(result)
|
||||||
|
result.forEach((mulString)=>{
|
||||||
|
const numRegex= /\d+/g
|
||||||
|
const numbers = mulString.match(numRegex)
|
||||||
|
console.log(...numbers)
|
||||||
|
const aVal =parseInt(numbers[0])
|
||||||
|
const bVal=parseInt(numbers[1])
|
||||||
|
total += aVal*bVal
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log("total: ",total)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue