Skip to content

Instantly share code, notes, and snippets.

Brian Chen betaveros

View GitHub Profile
@betaveros
betaveros / models.py
Created Jul 30, 2020
crude generic puzzlehunt models
View models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.db.models import OuterRef, Exists, Sum, Q
from django.core.validators import MinValueValidator
import django.urls as urls
@betaveros
betaveros / 1374-ac.cpp
Created Jul 15, 2020
UVA 1374: Power Calculus
View 1374-ac.cpp
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define fori(i,s,e) for(int i = s; i < ((int)e); i++)
#define allof(s) (s).begin(), (s).end()
const int MAX = 3000;
@betaveros
betaveros / 1374.cpp
Created Jul 8, 2020
UVA 1374: Power Calculus (TLE version. how to improve?)
View 1374.cpp
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define fori(i,s,e) for(int i = s; i < ((int)e); i++)
#define allof(s) (s).begin(), (s).end()
@betaveros
betaveros / 12558.cpp
Created Jul 8, 2020
UVA 12558: Egyptian Fractions
View 12558.cpp
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
#define fori(i,s,e) for(int i = s; i < ((int)e); i++)
long long gcd(long long x, long long y) {
return y == 0 ? x : gcd(y, x % y);
}
View gist:9663e49011a722e82e835b8d86234ee4
In [73]: for i in range(70):
...: print('C{} ='.format(i), end=" ")
...: try:
...: print(' '.join(pitch.nameWithOctave for pitch in ChordSymbol('C{}'.format(i)).pitches))
...: except Exception as e:
...: print(e)
...:
C0 = C3
C1 = C3 C3
C2 = C3 D3
View gist:48ed6e60c2a1562249dfbf29bfd85e19
major 40173
dominant 19633
minor 11501
minor-seventh 7156
major-seventh 2828
maj 1516
major-sixth 1442
dominant-ninth 1210
[] 1180
minor-sixth 692
@betaveros
betaveros / advent-2019-4.py
Created Dec 4, 2019
Advent of Code 2019 Day 4, DP solution
View advent-2019-4.py
"""
For part 1 for counting solutions ≤ x, our DP state can be dp[n][f][d][le] = the count of digit-strings with
- n digits
- where the first digit is f
- and a double digit has appeared iff d = 1
- that are less than equal to the last n digits of x iff le = 1.
"""
def part1_dp(x): # x should be list of digits
@betaveros
betaveros / mums-leaderboard.js
Last active Aug 10, 2019
Add comparable solve times to the MUMS Puzzlehunt leaderboard
View mums-leaderboard.js
(() => {window.setInterval(() => {
document.querySelectorAll('.betaveros').forEach((node) => {
node.parentNode.removeChild(node);
});
const makeNode = (t) => {
const span = document.createElement('span');
span.className = 'betaveros';
span.textContent = t;
return span;
};
@betaveros
betaveros / makefuzz.py
Created Apr 16, 2019
some really sketchy makefile patching to get openssl fuzzing to work
View makefuzz.py
import sys, os, subprocess
def check(msg):
if not input(msg + ' (y/n): ').lower().startswith('y'):
print('Aborting')
sys.exit()
subprocess.run('./config enable-fuzz-libfuzzer -DPEDANTIC enable-asan enable-ubsan no-shared -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=fuzzer-no-link enable-ec_nistp_64_gcc_128 -fno-sanitize=alignment enable-tls1_3 enable-weak-ssl-ciphers enable-rc5 enable-md2 enable-ssl3 enable-ssl3-method enable-nextprotoneg --debug'.split(), env={'CC': 'clang'})
check('Does config look ok?')
with open('Makefile') as infile:
You can’t perform that action at this time.