asterisk's recent activity
-
Comment on Which web browser do you use? in ~tech
-
Comment on Day 11: Monkey in the Middle in ~comp.advent_of_code
asterisk (edited )LinkPython import copy, math, operator, re monkeys = [] for line in open("input.txt").readlines(): line = line.strip() if line.startswith("Monkey"): monkeys.append([]) continue if...Python
import copy, math, operator, re monkeys = [] for line in open("input.txt").readlines(): line = line.strip() if line.startswith("Monkey"): monkeys.append([]) continue if line.startswith("Start"): monkeys[-1].append(list(map(int, re.findall("\d+", line)))) continue if line.startswith(("Test", "If")): monkeys[-1].append(int(re.search(r"\d+", line).group())) continue if line == "": continue monkeys[-1].append(line.split("= old ")[-1].split(" ")) ops = { "+": operator.add, "-": operator.sub, "*": operator.mul, "/": operator.truediv, } def operation(old, new): op, val = new val = old if val == "old" else int(val) return ops[op](old, val) def inspecting(isridiculous: bool = True): inspectors = copy.deepcopy(monkeys) activities = [0] * len(inspectors) magic = math.prod([inspector[2] for inspector in inspectors]) if isridiculous else 3 for _ in range(10_000 if isridiculous else 20): for m, (worries, new, isdiv, yeah, nope) in enumerate(inspectors): if len(worries) == 0: continue activities[m] += len(worries) for worry in worries: worry = operation(worry, new) worry = worry % magic if isridiculous else worry // magic inspectors[nope if worry % isdiv else yeah][0].append(worry) inspectors[m][0] = [] activities = sorted(activities) print(activities[-1] * activities[-2]) inspecting(False) # Part One: 56120 inspecting() # Part Two: 24389045529
-
Comment on Day 10: Cathode-Ray Tube in ~comp.advent_of_code
asterisk I had black out from 9 Dec to 22 Dec, yeah. But Iʼll try to do something. Python instructions: str = open("input.txt").read().split("\n") def execution(points: list, draw: bool = True): x: int = 1...I had black out from 9 Dec to 22 Dec, yeah. But Iʼll try to do something.
Python
instructions: str = open("input.txt").read().split("\n") def execution(points: list, draw: bool = True): x: int = 1 cycles: int = 1 output = str() if draw else int() for instruction in instructions: instruction = instruction.split(" ") for _ in instruction: if cycles in points: if draw: points.pop(0) else: output += x * cycles if draw: if cycles - 1 - points[0] in range(x - 1, x + 1 + 1): output += "#" else: output += "." cycles += 1 if len(instruction) > 1: x += int(instruction[1]) if draw: for h in range(high): print(output[h * wide : h * wide + wide]) else: print(output) execution([20, 60, 100, 140, 180, 220], False) # Part One: 15360 wide: int = 40 high: int = 6 execution([x for x in range(0, wide * high, wide)]) # Part Two: PHLHJGZA
-
Comment on Day 9: Rope Bridge in ~comp.advent_of_code
asterisk Python motions = open("input.txt").read().split("\n") routes = {"R": (1, 0), "L": (-1, 0), "U": (0, 1), "D": (0, -1)} def touching(knots, i): if not knots[i]: return (0, 0) px, py = knots[i - 1]...Python
motions = open("input.txt").read().split("\n") routes = {"R": (1, 0), "L": (-1, 0), "U": (0, 1), "D": (0, -1)} def touching(knots, i): if not knots[i]: return (0, 0) px, py = knots[i - 1] mx, my = knots[i] kx, ky = knots[i] for x in (mx - 1, mx, mx + 1): for y in (my - 1, my, my + 1): if x == px and y == py: return knots[i] if kx == px: ky += 1 if py - ky > 0 else -1 if ky == py: kx += 1 if px - kx > 0 else -1 if kx == mx and ky == my: kx += 1 if px - kx > 0 else -1 ky += 1 if py - ky > 0 else -1 return (kx, ky) def simulation(knots: int = 1) -> int: knots = [(0, 0)] + [None for _ in range(knots)] history = set() for motion in motions: route, steps = motion.split(" ") for _ in range(int(steps)): knots[0] = list(map(lambda a, b: a + b, knots[0], routes[route])) for i in range(1, len(knots), 1): knots[i] = touching(knots, i) history.add(knots[-1]) return len(history) print(simulation()) # Part One: 6470 print(simulation(9)) # Part Two: 2658
-
Comment on Day 8: Treetop Tree House in ~comp.advent_of_code
asterisk I had problem with electricity (almost all day) and work. But I still made it in this day, yahoo! Python grid = [[int(x) for x in y.strip()] for y in open("input.txt").readlines()] onview = [[0...I had problem with electricity (almost all day) and work. But I still made it in this day, yahoo!
Python
grid = [[int(x) for x in y.strip()] for y in open("input.txt").readlines()] onview = [[0 for _ in range(len(grid[0]))] for _ in range(len(grid))] def measure(m): return len(m[0]), len(m) def rotate(m): row, col = measure(m) for i in range(row // 2): m[i], m[col - i - 1] = m[col - i - 1], m[i] for i in range(row): for j in range(i): m[i][j], m[j][i] = m[j][i], m[i][j] return m for side in range(4): i, j = measure(grid) for y in range(i): tallest = grid[y][0] onview[y][0] = 1 for x in range(j): if grid[y][x] > tallest: tallest = grid[y][x] onview[y][x] = 1 elif grid[y][x] == 9: break else: continue if side == 4: break grid = rotate(grid) onview = rotate(onview) print(sum(map(sum, onview))) # Part One: 1543
grid = [[int(x) for x in y.strip()] for y in open("input.txt").readlines()] hor, ver = len(grid[0]), len(grid) scenes = [[1 for _ in range(hor)] for _ in range(ver)] def view(opt: int, length: int, route: int = 1) -> int: tallest: int = grid[y][x] trees: int = 0 m = list(zip(*grid) if opt else grid) i, j = (x, y) if opt else (y, x) for step in range(1, length): trees += 1 if tallest <= m[i][j + step * route]: break return trees for y in range(hor): for x in range(ver): for opts in [(0, ver - x), (0, x + 1, -1), (1, hor - y), (1, y + 1, -1)]: scenes[y][x] *= view(*opts) print(max(map(max, scenes))) # Part Two: 595080
Only one sad thing: I made it as two tasks, not combined. Maybe later I will try to make it as one.
-
Comment on Day 7: No Space Left On Device in ~comp.advent_of_code
asterisk Python import collections, copy def tree(): return collections.defaultdict(tree) filesystem = tree() path = list() dirs = set() def add(keys, value=None, t=filesystem): for i, key in...Python
import collections, copy def tree(): return collections.defaultdict(tree) filesystem = tree() path = list() dirs = set() def add(keys, value=None, t=filesystem): for i, key in enumerate(keys): if i == len(keys) - 1 and value: continue t = t[key] if value: t[key] = value def dirSize(keys): t = copy.deepcopy(filesystem) total = int() for k in keys: t = t[k] for k in t.keys(): total += t[k] if type(t[k]) == int else dirSize(keys + tuple([k])) return total for line in open("input.txt").read().splitlines(): match line.split(): case ["$", "cd", dir]: match dir: case "..": path.pop() case "/": path = ["/"] case _: path.append(dir) dirs.add(tuple(path)) add(path) case ["$", "ls"]: pass case ["dir", dir]: add(path + [dir]) dirs.add(tuple(path + [dir])) pass case [size, file]: add(path + [file], int(size)) limit: int = 100_000 total_space: int = 70_000_000 need_space: int = 30_000_000 total = int() for_delete = list() need_space -= total_space - dirSize(tuple("/")) for dir in dirs: size = dirSize(dir) if size < limit: total += size if size > need_space: for_delete.append(size) print(total) # Part One: 1325919 print(min(for_delete)) # Part Two: 2050735
Yeah, it was harder for me: I donʼt like trees; and at begining I had problem with electricity at the morning. Iʼll try to make the code cleaner but it kinda work, so for now itʼs fine.
-
Comment on Weekly megathread for news/updates/discussion of Russian invasion of Ukraine - December 1 in ~news
asterisk Heh, indeed. Saint Nicholas itʼs basically Orthodox Santa Claus. Religious people pray; children find something under their pillow. Itʼs usually, if in socks itʼs more like West influence (I have...My guess is that nowadays, every day is Armed Forces day? :)
Heh, indeed.
How are these days celebrated?
Saint Nicholas itʼs basically Orthodox Santa Claus. Religious people pray; children find something under their pillow. Itʼs usually, if in socks itʼs more like West influence (I have nothing against), and near the three — itʼs more about New Year, thereʼre no presents at Christmas. So, good ones get a present; and bad ones get a birch road. In Old Julian itʼs celebreted (and most do this) in 19th December (for now, you basically add ± 14 days), but thereʼs some shift:
- Politically: itʼs mostly just away from Russia,
- Pragmatically: not only because the calendar is old; even for religious people, because celebreting New Year is a «a New Year table» when many people (usually a familly) gathering to eat very much, but thereʼs Philip's Fast which doesnʼt allow eat some dish.
Just an interesting facts:
- Maybe you hear about city Mykolayiv which was at the front on the south, it just basically means Mykolayʼs where Mykolay is after Nicholas, yeah, in this case this saint.
- In jokes itʼs includes to cycle of Winter holidays: Saint Nicholaus, New Christmas (which also includes Christmas Eve), New Year (includes Malanka, btw, Carol of the Bells is part of this), Old Christmas (the same), Old New Year (the same), Iordan. Yeah…
If speak about Armed Forces of Ukraine then itʼs cellebreted usually by congratulation (from people and goverment in different forms) and by words full of thanks.
-
Comment on Weekly megathread for news/updates/discussion of Russian invasion of Ukraine - December 1 in ~news
asterisk In Ukraine today is Days of: Saint Nicholas (in New Julian or Gregorian calendar), Armed Forces of Ukraine.In Ukraine today is Days of:
- Saint Nicholas (in New Julian or Gregorian calendar),
- Armed Forces of Ukraine.
-
Comment on Day 6: Tuning Trouble in ~comp.advent_of_code
asterisk Python buffer = open("input.txt").read() def device(length: int): for i in range(len(buffer) - length + 1): if len(set(buffer[i : i + length])) == length: return length + i print(device(4)) # Part...Python
buffer = open("input.txt").read() def device(length: int): for i in range(len(buffer) - length + 1): if len(set(buffer[i : i + length])) == length: return length + i print(device(4)) # Part One: 1625 print(device(14)) # Part Two: 2250
-
Comment on Day 5: Supply Stacks in ~comp.advent_of_code
asterisk (edited )LinkPython from curses.ascii import isdigit import collections, copy, re file = [block.split("\n") for block in open("input.txt").read().split("\n\n")] procedures = [list(map(int, re.findall("\d+",...Python
from curses.ascii import isdigit import collections, copy, re file = [block.split("\n") for block in open("input.txt").read().split("\n\n")] procedures = [list(map(int, re.findall("\d+", line))) for line in file[1]] crates = collections.defaultdict(list) for line in file[0][-2::-1]: for i, mark in enumerate(file[0][-1]): if isdigit(mark) and i < len(line) and line[i] != " ": crates[int(mark)].append(line[i]) def crateMover(version: int = 9000) -> str: cell = copy.deepcopy(crates) for move, a, b in procedures: moved = [cell[a].pop() for _ in range(move)] cell[b].extend(moved if version == 9000 else moved[::-1]) return "".join([cell[i][-1] for i in cell]) print(crateMover()) # Part One: QNHWJVJZW print(crateMover(9001)) # Part Two: BPCZJLFJW
Update
Fromfor line in file[0][-2::-1]: for i, mark in [(i, int(mark)) for i, mark in enumerate(file[0][-1]) if isdigit(mark)]: if i >= len(line): break elif line[i] != " ": crates[mark].append(line[i])
To
for line in file[0][-2::-1]: for i, mark in enumerate(file[0][-1]): if isdigit(mark) and i < len(line) and line[i] != " ": crates[int(mark)].append(line[i])
Yeah, the parsing took more time than both solutions…
-
Comment on Day 4: Camp Cleanup in ~comp.advent_of_code
asterisk (edited )LinkPython import re def cleanup(full: bool = True) -> int: overlap: int = 0 for line in open("input.txt"): a, b, c, d = map(int, re.findall(r"\d+", line)) first = set(range(a, b + 1)) second =...Python
import re def cleanup(full: bool = True) -> int: overlap: int = 0 for line in open("input.txt"): a, b, c, d = map(int, re.findall(r"\d+", line)) first = set(range(a, b + 1)) second = set(range(c, d + 1)) if first.issubset(second) or second.issubset(first) if full else first.intersection(second): overlap += 1 return overlap print(cleanup()) # Part One: 498 print(cleanup(False)) # Part Two: 859
Updated
- if full and (first.issubset(second) or second.issubset(first)) or not full and first.intersection(second): + if first.issubset(second) or second.issubset(first) if full else first.intersection(second):
-
Comment on Day 3: Rucksack Reorganization in ~comp.advent_of_code
asterisk Python import string from collections import Counter from functools import reduce from operator import and_ insert = open("input.txt").read().split() def reorganization(length: int, count: int =...Python
import string from collections import Counter from functools import reduce from operator import and_ insert = open("input.txt").read().split() def reorganization(length: int, count: int = 1) -> int: priorities: int = 0 for line in range(0, len(insert) - count + 1, count): parts = list() for n in range(count): l = len(insert[line + n]) // length for div in range(0, len(insert[line + n]), l): parts.append(Counter(insert[line + n][div : div + l])) item = list(reduce(and_, parts).elements())[0] priorities += string.ascii_letters.index(item) + 1 return priorities print(reorganization(2)) # Part One: 7889 print(reorganization(1, 3)) # Part Two: 2825
-
Comment on Day 2: Rock Paper Scissors in ~comp.advent_of_code
asterisk Python by_selected: int = 0 by_outcome: int = 0 selected = { "X": 1, "Y": 2, "Z": 3, } outcome = { "A": [3, 6, 0], "B": [0, 3, 6], "C": [6, 0, 3], } with open("input.txt") as file: for line in...Python
by_selected: int = 0 by_outcome: int = 0 selected = { "X": 1, "Y": 2, "Z": 3, } outcome = { "A": [3, 6, 0], "B": [0, 3, 6], "C": [6, 0, 3], } with open("input.txt") as file: for line in file: elf, me = line.split() by_selected += selected[me] + outcome[elf][selected[me] - 1] result = (selected[me] - 1) * 3 by_outcome += result + outcome[elf].index(result) + 1 print(by_selected) # Part One: 10941 print(by_outcome) # Part Two: 13071
-
Comment on Day 1: Calorie Counting in ~comp.advent_of_code
asterisk Python, nothing special. with open("input.txt") as file: elves = [0] for line in file: line = line.strip() if line: elves[-1] += int(line) else: elves.append(0) elves = sorted(elves)...Python, nothing special.
with open("input.txt") as file: elves = [0] for line in file: line = line.strip() if line: elves[-1] += int(line) else: elves.append(0) elves = sorted(elves) print(elves[-1]) # Part One: 68442 print(sum(elves[-3:])) # Part Two: 204837
-
Comment on Re-Nav: a WebExtension to create custom redirects for any website in ~tech
asterisk (edited )LinkSorry, Iʼm late but thereʼs Redirector. Iʼve already use it for some purposes: Mobile → desktop version: ^(https?://)([a-z0-9-]*\.)?m(?:obile)?\.(.*) → $1$2$3 Because some sites cannʼt do it...I've looked around for other extensions that can do this, but haven't really found anything like it. There's a few that redirect all requests, but I only want the navigation ones to count. There are a few that do this for specific sites, like Old Reddit Redirect. But none I've found that do this for anything you want.
Sorry, Iʼm late but thereʼs Redirector.
Iʼve already use it for some purposes:
-
Mobile → desktop version:
^(https?://)([a-z0-9-]*\.)?m(?:obile)?\.(.*)
→$1$2$3
Because some sites cannʼt do it themselves — hello, Wikipedia! Usually itʼs enough.
-
Change language
-
Change to some alternative site like:
(https?://)(.*)?\.medium\.com/(.*)
→$1scribe.rip/$3
-
-
Comment on What have you been watching / reading this week? (Anime/Manga) in ~anime
asterisk Finished Higurashi no Naku Koro ni Kai.Finished Higurashi no Naku Koro ni Kai.
-
Comment on What are the top five software apps you benefit the most from? in ~tech
asterisk Kitty — a terminal, Menyoki — a screen shotter, MPV — a video player, Transmission — a torrent client, Wine — a program runner.- Kitty — a terminal,
- Menyoki — a screen shotter,
- MPV — a video player,
- Transmission — a torrent client,
- Wine — a program runner.
-
Comment on Oskar Schuster - Odesa (2022) in ~music
asterisk If youʼre interesting what thereʼs typed at 1:20 then thereʼre collected байкиukr by Борис Грінченко (Василь Чайченко is one of among his pseudos). The book, the fable names: Горобцї та кіт...- Exemplary
If youʼre interesting what thereʼs typed at 1:20 then thereʼre collected байкиukr by Борис Грінченко (Василь Чайченко is one of among his pseudos). The book, the fable names:
- Горобцї та кіт «Sparrows and a cat», p. 40;
- Журавель та горобець «A crane and a sparrow», p. 49.
The spellingukr (a little in English) of Желехівськогоukr (ofc, Ukrainian language) is used.
-
Comment on What have you been watching / reading this week? (Anime/Manga) in ~anime
asterisk Chainsaw Man was added to my ongoing watch list.Chainsaw Man was added to my ongoing watch list.
-
Comment on What have you been watching / reading this week? (Anime/Manga) in ~anime
asterisk New in Fall Season, what I liked from the first episodes: Akiba Maid Sensou. In my opinion, the best first episode, I laughed so much. Bocchi the Rock! where rock as music. Do It Yourself!! Human...New in Fall Season, what I liked from the first episodes:
- Akiba Maid Sensou. In my opinion, the best first episode, I laughed so much.
- Bocchi the Rock! where rock as music.
- Do It Yourself!!
- Human Bug Daigaku. Iʼm not sure, but I let to try the second episode.
New seasons:
Ungoogled Chromium or just Google Chrome. It better intergrated into Linux from box or with a little fixes than f.e. Firefox like function with mouse midle clicks which I used. Also Chromium works better on slow machines or itʼs just my feels. And itʼs Firefox on Android because of extentions but maybe Iʼll review here later if I find something fine.
If about my browser history, then it was so: IE > Firefox ~ Opera (Presto) > Google Chrome (from the first versions).