[ / / ] [ b / int ] [ a / fo / g / mu / t ] [ visi / meta ]

/g/ - Technologijos ir Žaidimai

Vardas
El. paštas
Tema
Žinutė
Failas
Įterpti
CAPTCHA
Parinktys
(Slaptažodis ištrynimui / redagavimui)

      

1701470150648.gif (3,02 MB, 450x296, pahmas.gif)

/aoc/ Advent Of Code 2023 Anonimas  Nr.90

https://adventofcode.com/2023

ar dalyvausit šiais metais virai ? dalinames sprendimais ~~

1 diena :
import re

sum = 0
i = 1
spellednumbers = [['zero', '0'], ['one', '1'], ['two', '2'], ['three', '3'], ['four', '4'], ['five', '5'], ['six', '6'], ['seven','7'], ['eight', '8'], ['nine', '9']]
numberRegex = r'\d|one|two|three|four|five|six|seven|eight|nine'

with open('input.txt') as inputFile:
f = open("output1.txt", "w")
for line in inputFile:
matchBuffer = []

#start regex pattern matching, if we find a spelled digit we check if it overlaps with another
for match in re.finditer(numberRegex, line):
s = match.start()
e = match.end()
matchBuffer.append(line[s:e])
if line[s:e].isnumeric() == False:
for spelledNumber in spellednumbers:
number = spelledNumber[0]
overlappingIndex = e - 1
overlapped = line.find(number, overlappingIndex, overlappingIndex + len(number))
if overlapped != -1:
#we found overlapping digit, add it to buffer
sub = line[overlapped:overlapped + len(number)]
matchBuffer.append(sub)
break


firstDig = matchBuffer[0]
secondDig = matchBuffer[len(matchBuffer) - 1]

#find numeric value for first digit
for index, number in enumerate(spellednumbers):
if firstDig in number:
firstDig = str(index)
break

#find numeric value for second digit
for index, number in enumerate(spellednumbers):
if secondDig in number:
secondDig = str(index)
break

result = firstDig + secondDig
sum+=int(result)
i+=1
f.write("["+ line.strip() + "] -> " + str(matchBuffer) + " -> " + result + "\n")
f.write("sum of calibration values: " + str(sum))
f.close()

Anonimas  Nr.91

1701530545908.png (4,38 MB, 1600x2048, 138566969_160494458881384_….png)

2 diena :

import re

redThresh = 12
greenThresh = 13
blueThresh = 14

red = []
green = []
blue = []

idSum = 0
powerSum = 0
with open('input.txt') as inputFile:
f = open("output.txt", "w")
for line in inputFile:
gameRBuffer = []
gameBBuffer = []
gameGBuffer = []
game = line.split(": ")
gameId = re.findall(r'\d+', game[0])
sets = game[1].split("; ")
for set in sets:
cubes = re.findall(r'\d+ \w+', set)
for cube in cubes:
if cube.find('red') != -1:
number = re.findall(r'\d+', cube)
gameRBuffer.append(int(number[0]))
if cube.find('blue') != -1:
number = re.findall(r'\d+', cube)
gameBBuffer.append(int(number[0]))
if cube.find('green') != -1:
number = re.findall(r'\d+', cube)
gameGBuffer.append(int(number[0]))
red.append(gameRBuffer)
green.append(gameGBuffer)
blue.append(gameBBuffer)
possibleR = all(i <= redThresh for i in gameRBuffer)
possibleG = all(i <= greenThresh for i in gameGBuffer)
possibleB = all(i <= blueThresh for i in gameBBuffer)
possible = (possibleR and possibleG and possibleB)
if possible == True:
idSum += int(gameId[0])

fewestR = sorted(gameRBuffer, reverse=True)[0]
fewestG = sorted(gameGBuffer, reverse=True)[0]
fewestB = sorted(gameBBuffer, reverse=True)[0]

power = fewestG * fewestR * fewestB
powerSum += power

f.write("[{}] -> R{} G{} B{} -> Possible : {} -> Fewest [R {}, G {}, B {}]\n".format(
str(gameId[0]),
str(gameRBuffer),
str(gameGBuffer),
str(gameBBuffer),
str(possible),
str(fewestR),
str(fewestG),
str(fewestB)))
f.write("Sum of all possible game IDs -> {}\n".format(str(idSum)))
f.write("Sum of fewest set of cubes powers -> {}\n".format(str(powerSum)))
f.close()

Unikalūs IP: 1


    [Post a Reply]
[ ]   
 
[ / / ] [ b / int ] [ a / fo / g / mu / t ] [ visi / meta ]