$ ./alltests_reg generate
Running alltests_reg:
This currently tests 129 of the 129 regression test
programs in the /prog directory.
////////////////////////////////////////////////
//////////////// adaptmap_reg ///////////////
////////////////////////////////////////////////
leptonica-1.79.0 : libgif 5.1.4 : libjpeg 9c : libpng 1.6.37 : libtiff 4.0.10 : zlib 1.2.11 : libwebp 1.0.2 : libopenjp2 2.3.1
This file contains 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
// Run in https://thebookofshaders.com/edit.php#11/ | |
// TODO: | |
// - would be nice to just use the polygon instead of triangle | |
// + keeping track of the orientation as one descends to lower levels | |
// - to put the borders | |
// - to normalize the width/height regardless of zoom level | |
// + probably find the biggest tile containing the tiles of given size on the Xth level | |
// - add other tiles | |
#ifdef GL_ES |
This file contains 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
g = [] | |
for line in open('day12.input'): | |
g.append([ord(c) for c in line.strip()]) | |
n = len(g) | |
# find S and E and transform to ord('a') and ord('z') | |
s, e = None, None | |
for i in range(n): | |
for j in range(len(g[i])): | |
if g[i][j] == ord('S'): | |
g[i][j] = ord('a') |
This file contains 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 std/strutils | |
import std/sequtils | |
type Loc = tuple | |
x, y: int | |
proc parseGrid(): tuple[s: Loc, e: Loc, g: seq[seq[int]]] = | |
var | |
g: seq[seq[int]] | |
s, e: Loc |
This file contains 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
interface AleaPRNG { | |
float32: () => number; | |
uint32: () => number; | |
fract53: () => number; | |
gaussian: (mean?: number, std?: number) => number; | |
} | |
/** | |
* Alea PRNG that is not cryptographically secure. | |
*/ | |
export const mkAlea = (seed: string): AleaPRNG => { |
This file contains 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
#define phi 1.61803398874989484820 | |
#define h 1.53884176858762670128 | |
uniform float time; | |
varying vec2 vUv; | |
varying vec3 vNormal; | |
float cx(in vec2 a, in vec2 b) { | |
return a.x * b.y - a.y * b.x; | |
} |
This file contains 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
# ts, ds = [[int(i) for i in l.split()[1:]] for l in open(0).read().split('\n') if l] # part 1 | |
ts, ds = [[int(i) for i in [''.join(l.split()[1:])]] for l in open(0).read().split('\n') if l] # part 2 | |
def binary_search(f, l, r): | |
while l < r: | |
m = (l+r)//2 | |
if f(m): | |
l = m+1 | |
else: | |
r = m |
This file contains 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 Counter | |
SND = True # False for part 1 | |
def hand(cnts: Counter): | |
if SND and 'J' in cnts: | |
for c, _ in cnts.most_common(2): | |
if c == 'J': continue | |
cnts[c] += cnts['J'] | |
cnts.pop('J', 0) |
This file contains 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
G = open(0).read().splitlines() | |
N, M = len(G), len(G[0]) | |
# dest needs to be valid and the dest direction change is predetermined | |
# (dx, dy, valid_dest, next MS index) | |
MS = [(1, 0, "|LJS", [0, 1, 3, 2]), (0, 1, "-J7S", [1, 2, 0, 3]), | |
(-1, 0, "|7FS", [2, 3, 1, 0]), (0, -1, "-FLS", [3, 0, 2, 1])] | |
sj, si = max((l.find('S'), i) for i, l in enumerate(G)) | |
best = 0, 0 | |
for d in range(3): # trying 3 directions is enough |
This file contains 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
def collect(u): | |
ri, i = [], 0 | |
for r in u: | |
n = r.count('#') | |
if n: ri.extend([i]*n) | |
i += 1 if n else D | |
return ri | |
D = 1000000 # 2 # for part 1 | |
manhattan_sum = lambda xs: sum((1+i+i-len(xs))*x for i, x in enumerate(xs)) |
OlderNewer