This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SESSION_EXISTS=$(tmux list-sessions 2>/dev/null | grep -c "^svc:") | |
| if [ "$SESSION_EXISTS" -eq 0 ]; then | |
| tmux new-session -d -s svc -n sshd '/usr/sbin/sshd -D -e -E /dev/stderr' | |
| tmux new-window -t svc -n locstream 'cat /dev/location > /dev/null' | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # island finding with disjoint set union https://judge.yosupo.jp/submission/113653 | |
| from collections import defaultdict, Counter | |
| class DSU: | |
| def __init__(self, n): | |
| self.par = list(range(n)) | |
| self.size = [1]*n | |
| def find(self, x): | |
| bkx = x | |
| while x != self.par[x]: | |
| x = self.par[x] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ITERATIVE backtracking + pruning | |
| import math | |
| def decompose(n): | |
| stk = [ [n**2, n-1] ] # "function stack", (squared, internal counter i (next number can't be larger or equal to...)) | |
| while stk: | |
| squared, internal_counter_i = stk[-1] | |
| if squared == 0: | |
| stk.pop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| def decompose(n): | |
| res = None | |
| ss = [] | |
| def rec(squared, next_number_cannot_be_larger_than): | |
| nonlocal res | |
| if res: return | |
| if squared == 0: | |
| res = ss[::-1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # No two skyscrapers in a row or column may have the same number of floors | |
| # The height of the skyscrapers is between 1 and 4 | |
| # so conservative upper bound is (4!)**4 = 331776 | |
| # A clue is the number of skyscrapers you can see. | |
| import itertools | |
| n=4 | |
| def solve_puzzle (clues): | |
| grid=[] | |
| def validate_column(clue, c, from_top): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Compiles with gcc -Wall -O2 -o wavwrite wavwrite.c*/ | |
| // Modified from https://stackoverflow.com/questions/23030980/creating-a-stereo-wav-file-using-c | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <stdint.h> | |
| #include <limits.h> | |
| #include <math.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # aoc_2022_day_24_tf.py | |
| from collections import * | |
| import math, sys, copy, functools, json, re | |
| # In one minute, each blizzard moves one position in the direction it is pointing: | |
| DIRS = [(0,-1),(-1,0),(0,1),(1,0)] | |
| blizzards = defaultdict(list) # pos to direction | |
| # f = open("day24.input") | |
| f = open("day24_2.input") | |
| grid = [] | |
| for line in f: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import * | |
| import math, sys, copy, functools, json | |
| # !!! ONE ore-collecting robot in your pack that you can use to kickstart the whole operation | |
| # which blueprint would maximize the number of opened geodes after 24 minutes | |
| # needs at least 16GB ram to run pt 2... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import * | |
| import math | |
| class DSU_Iterative_By_Size: | |
| """Iterative find, rank by size, and path compression | |
| https://judge.yosupo.jp/submission/113655""" | |
| def __init__(self, n): | |
| self.par = list(range(n)) | |
| self.size = [1] * n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Compiles with gcc -Wall -O2 -o wavwrite wavwrite.c*/ | |
| // Modified from https://stackoverflow.com/questions/23030980/creating-a-stereo-wav-file-using-c | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <stdint.h> | |
| #include <limits.h> | |
| #include <math.h> |
NewerOlder