Appreciate the offer, but we want to try to avoid another situation with reports not being seen by mods for weeks.
Added as a moderator, we will likely add at least one more if there are more volunteers showing up.
Feels like the challenges are getting easier than harder currently. Fairly straightforward when doing it the lazy way with python. ::: spoiler Python
import re
winning_number_pattern: re.Pattern = re.compile(r' +([\d ]*?) +\|')
lottery_number_pattern: re.Pattern = re.compile(r'\| +([\d ]*)')
def get_winning_numbers(line: str) -> set[str]:
return set(winning_number_pattern.search(line).group(1).split())
def get_lottery_numbers(line: str) -> set[str]:
return set(lottery_number_pattern.search(line).group(1).split())
def get_winnings(winning_numbers: set[str], lottery_numbers: set[str]) -> int:
return int(2 ** (len(winning_numbers.intersection(lottery_numbers)) - 1))
def puzzle_1() -> int:
points: int = 0
with open('day4_scratchcards.txt', 'r', encoding='utf-8') as file:
for line in file:
points += get_winnings(get_winning_numbers(line), get_lottery_numbers(line))
return points
class ScratchCard:
def __init__(self, line: str):
self.amount: int = 1
self.winnings: int = len(get_winning_numbers(line).intersection(get_lottery_numbers(line)))
def update(self, extra: int) -> None:
self.amount = self.amount + extra
def __radd__(self, other):
return self.amount + other
def puzzle_2() -> int:
scratch_card_list: list[ScratchCard] = []
with open('day4_scratchcards.txt', 'r', encoding='utf-8') as file:
for line in file:
scratch_card_list.append(ScratchCard(line))
for i, scratch_card in enumerate(scratch_card_list):
for j in range(1, scratch_card.winnings + 1):
try:
scratch_card_list[i + j].update(scratch_card.amount)
except IndexError:
pass
return sum(scratch_card_list)
if __name__ == '__main__':
print(puzzle_1())
print(puzzle_2())
Could some communication issues between lemmy.ml and programming.dev, but the post is unfortunately not marked properly on our instance
Might as well start with a solid foundation from the start though. The extra work is minimal so there isn't much of a time cost to it. I wouldn't call it overengineering, it's just a different way to write code, and the way many naturally default to without really thinking about it.
Yeah, it's probably cheaper than than counting the number of comments since a timestamp though. Pure conjecture on my part though, haven't really done much stuff with SQL.
Salty? I listed a bunch of games that are clearly made by passionate developers and have been part of defining of defining the space in recent history. You are the one leaving a snarky comment that I listed less than 1 percent of games as if that proves anything.
Bing works with vpn. At least if you are logged in
Stockholm syndrome from whatever the convention is for your daily programming language. Long live snake case 🐍
Just be a decent human being and use type hints in python, problem solved.
Well that was quick. I barely had the time to look it up and edit my comment lol.
Thanks, appreciate the response.
Per our Code of Conduct, please avoid insulting users when commenting on our instance, even if "they started it".