Reinited repo because commits leaked my real name
This commit is contained in:
commit
700ba0888e
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,32 @@
|
|||
import fs from 'node:fs'
|
||||
|
||||
fs.readFile('input', 'utf8', (err, data) => {
|
||||
let cleanedData = []
|
||||
data.split(/(\r?\n){2,}/gm).forEach(data => {
|
||||
if(data !== '\n'){
|
||||
cleanedData.push(data.split('\n').map(n => {return Number(n)}))
|
||||
}
|
||||
})
|
||||
let highestValues = findHighest(cleanedData)
|
||||
console.log('Part 1: The elve with the most calories carries: ' + highestValues[0] + ' calories')
|
||||
let sumTop3 = highestValues[0]
|
||||
for(let i = 0; i < 2; i++) {
|
||||
cleanedData.splice(highestValues[1], 1)
|
||||
highestValues = findHighest(cleanedData)
|
||||
sumTop3 += highestValues[0]
|
||||
}
|
||||
console.log('Part 2: The three elves with the most calories carry: '+ sumTop3 + ' calories')
|
||||
})
|
||||
|
||||
function findHighest(numberArray) {
|
||||
let highestNumber = 0
|
||||
let highestIndex = 0
|
||||
numberArray.forEach((part, index) => {
|
||||
let sum = part.reduce((a, b) => a + b, 0)
|
||||
if (sum > highestNumber) {
|
||||
highestNumber = sum
|
||||
highestIndex = index
|
||||
}
|
||||
})
|
||||
return [highestNumber, highestIndex]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,3 @@
|
|||
A Y
|
||||
B X
|
||||
C Z
|
Binary file not shown.
|
@ -0,0 +1,35 @@
|
|||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val inputStream: InputStream = File("input").inputStream()
|
||||
val lineList = mutableListOf<Int>()
|
||||
inputStream.bufferedReader().forEachLine{
|
||||
val janken: List<String> = it.split(" ").map { when(it) {
|
||||
"X" -> "A"
|
||||
"Y" -> "B"
|
||||
"Z" -> "C"
|
||||
else -> it
|
||||
}}
|
||||
var score: Int = when (janken[1]) {
|
||||
"A" -> 1
|
||||
"B" -> 2
|
||||
"C" -> 3
|
||||
else -> 0
|
||||
}
|
||||
if (janken[0] == janken[1]) {
|
||||
score += 3
|
||||
} else if (janken[0] == "A") {
|
||||
score += if (janken[1] == "C") 6 else 0
|
||||
} else if (janken[0] == "B") {
|
||||
score += if (janken[1] == "A") 6 else 0
|
||||
} else if (janken[0] == "C") {
|
||||
score += if (janken[1] == "B") 6 else 0
|
||||
}
|
||||
println(janken)
|
||||
lineList.add(score)
|
||||
}
|
||||
println("My score will be " + lineList.sum())
|
||||
println(lineList.size)
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
import fs from 'node:fs'
|
||||
import readline from 'node:readline'
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: fs.createReadStream('input'),
|
||||
output: process.stdout,
|
||||
terminal: false
|
||||
})
|
||||
|
||||
let completeScore = 0
|
||||
rl.on('line', line => {
|
||||
let score = 0
|
||||
let janken = line.split(' ').map(symbol => unencrypt(symbol))
|
||||
switch(janken[1]) {
|
||||
case 'Rock':
|
||||
score += 1
|
||||
break
|
||||
case 'Paper':
|
||||
score += 2
|
||||
break
|
||||
case 'Scissors':
|
||||
score += 3
|
||||
break
|
||||
}
|
||||
if (janken[0] === janken[1]) {
|
||||
score += 3
|
||||
} else if (janken[0] === 'Rock') {
|
||||
if (janken[1] === 'Paper') {
|
||||
score += 6
|
||||
}
|
||||
} else if (janken[0] === 'Paper') {
|
||||
if (janken[1] === 'Scissors') {
|
||||
score += 6
|
||||
}
|
||||
} else if (janken[0] === 'Scissors') {
|
||||
if (janken[1] === 'Rock') {
|
||||
score += 6
|
||||
}
|
||||
}
|
||||
janken.push(score)
|
||||
console.log(janken)
|
||||
completeScore += score
|
||||
})
|
||||
|
||||
rl.on('close', () => {
|
||||
console.log("The complete score is: " + completeScore)
|
||||
})
|
||||
|
||||
function unencrypt(encSymbol) {
|
||||
let symbol
|
||||
switch (encSymbol) {
|
||||
case 'A':
|
||||
case 'X':
|
||||
symbol = 'Rock'
|
||||
break
|
||||
case 'B':
|
||||
case 'Y':
|
||||
symbol = 'Paper'
|
||||
break
|
||||
case 'C':
|
||||
case 'Z':
|
||||
symbol = 'Scissors'
|
||||
break
|
||||
}
|
||||
return symbol
|
||||
}
|
Loading…
Reference in New Issue