Skip to content

Instantly share code, notes, and snippets.

View spdskatr's full-sized avatar

spdskatr

  • University of Cambridge
View GitHub Profile
@spdskatr
spdskatr / qm.hs
Last active May 5, 2022 12:40
Haskell implementation for boolean logic simplification.
-- Implements (loosely) the QM method for boolean logic simplification.
--
-- Encode minterms as integers.
--
-- Implicants are sets of integers (think SOP form)
--
-- Combining two terms means that their bits differ by 1 and their don't
-- care conditions are in the same place, which translates in our model
-- to "when matched in order, every pair of elements from both sets have
-- the same XOR difference and the XOR difference is a power of two"
@spdskatr
spdskatr / amt_code_of_conduct.txt
Created March 30, 2021 11:45
AMT Code of Conduct
Part A – AMT Student Code of Conduct
The Australian Maths Trust (AMT) undertakes a range of varied mathematical and informatics activities for students in primary and secondary school including: competitions, enrichment activities, student and teacher workshops, training schools, and various government STEM enrichment initiatives (digIT and Curious Minds).
The physical, mental and emotional safety and wellbeing of students, staff and volunteers engaged with all AMT activities is of paramount importance to the AMT. All students are entitled to participate in AMT activities in a safe environment and expected to behave in such a manner that creates a safe, productive and friendly environment.
Students engaged in any AMT activity will:
1. remember they are representing themselves, their school and family communities and, if selected to an Olympiad team, Australia
2. behave appropriately, including showing respect to others, acting with integrity and honesty and conducting themselves in a manner that does not
@spdskatr
spdskatr / hungarian.cpp
Created October 10, 2020 11:08
Hungarian Algorithm O(N^4) implementation in C++
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
using namespace std;
@spdskatr
spdskatr / microlovania.py
Last active November 2, 2024 01:38
Megalovania for the bbc micro:bit.
from microbit import *
import music
import radio
MEGALOVANIA2 = "D3:2 D3:2 D4:4 A3:5 0:1 G#3:4 G3:4 F3:4 D3:2 F3:2 G3:2 C3:2 C3:2 D4:4 A3:5 0:1 G#3:4 G3:4 F3:4 D3:2 F3:2 G3:2 B2:2 B2:2 D4:4 A3:5 0:1 G#3:4 G3:4 F3:4 D3:2 F3:2 G3:2 A#2:2 A#2:2 D4:4 A3:5 0:1 G#3:4 G3:4 F3:4 D3:2 F3:2 G3:2 D4:2 D4:2 D5:4 A4:5 0:1 G#4:4 G4:4 F4:4 D4:2 F4:2 G4:2 C4:2 C4:2 D5:4 A4:5 0:1 G#4:4 G4:4 F4:4 D4:2 F4:2 G4:2 B3:2 B3:2 D5:4 A4:5 0:1 G#4:4 G4:4 F4:4 D4:2 F4:2 G4:2 A#3:2 A#3:2 D5:4 A4:5 0:1 G#4:4 G4:4 F4:4 D4:2 F4:2 G4:2 F4:4 F4:2 F4:4 F4:4 F4:4 D4:4 D4:8 D4:2 F4:4 F4:2 F4:4 G4:4 G#4:4 G4:2 F4:2 D4:2 F4:2 G4:2 0:4 F4:4 F4:2 F4:4 G4:4 G#4:4 A4:4 C5:4 A4:6 D5:4 D5:4 D5:2 A4:2 D5:2 C5:16 A4:4 A4:2 A4:4 A4:4 A4:4 G4:4 G4:8 G4:2 A4:4 A4:2 A4:4 A4:4 G4:4 A4:4 C5:4 A4:2 G4:4 D5:2 D4:2 A4:2 D4:2 G4:2 D4:2 F4:2 D4:2 C5:2 C4:2 G4:2 C4:2 F4:2 B3:2 E4:2 B3:2 A#3:6 C4:2 D4:2 F4:4 C5:16 0:16 F4:2 D4:2 F4:2 G4:2 G#4:2 G4:2 F4:2 D4:2 G#4:2 G4:2 F4:2 D4:2 F4:4 G4:16 G#4:4 A4:2 C5:4 A4:2 G#4:2 G4:2 F4:2 D4:2 E4:2 F4:4 G4:4 A4:4 C5:4 C#5:4 G#4:4
alphabet = "abcdefghijklmnopqrstuvwxyz"
syllables = "ing er a ly ed i es re tion in e con y ter ex al de com o di en an ty ry u ti ri be per to pro ac ad ar ers ment or tions ble der ma na si un at dis ca cal man ap po sion vi el est la lar pa ture for is mer pe ra so ta as col fi ful get low ni par son tle day ny pen pre tive car ci mo an aus pi se ten tor ver ber can dy et it mu no ple cu fac fer gen ic land light ob of pos tain den ings mag ments set some sub sur ters tu af au cy fa im li lo men min mon op out rec ro sen side tal tic ties ward age ba but cit cle co cov daq dif ence ern eve ies ket lec main mar mis my nal ness ning n't nu oc pres sup te ted tem tim tri tro up"
def caesar_decipher(text):
text = text.lower()
results = [] # Item 0 is score, item 1 is text
for i in range(26): # Decode ciphertext, then record number of commonly used syllables present, favouring longer syllables
decoded = "".join([(alphabet[i:] + alphabet[:i])[alphabet.index(c)] if c in alphabet else c for c
@spdskatr
spdskatr / treap.cpp
Last active May 14, 2019 07:29
Implementation of a randomised binary search tree in C++ with arbitrary insertion/deletion updates and range max queries
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int root, al = 1;
struct tree { int val, data, l, r, cnt, rmq; } tr[1000005];
void upd(int n) {
@spdskatr
spdskatr / golf_gophers.cpp
Created April 14, 2019 13:39
GCJ 2019 Round 1A Problem 2 "Golf Gophers" solution with N = 6
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int T, N, M, sieve[1000005];
int q[6] = { 17, 9, 7, 11, 13, 16 };
int res[6];
@spdskatr
spdskatr / dat.cpp
Last active April 7, 2019 05:01
GCJ 2019 Qualifier Problem 4 "Dat Bae" solution with F = 4
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
int T, a[1024], tc[4][1024], tb[1024];
from microbit import *
# State: 0 if on standby (waiting for button), 1 if active (waiting for shake)
state = 0
# The time button A was pressed, in milliseconds
last_press = 0
# Target image on display means it's in standby state, stick figure image on display means it's in active state
display.show(Image.TARGET)
@spdskatr
spdskatr / cpp_formatter.py
Created March 3, 2019 11:30
Makes your C++ code look a whole lot prettier. Usage: `./cpp_formatter.py (L|R|J) <width>`
#!/usr/bin/env python2
# "Justifies" your C++ code
# Warning: It might split some strings in half :P
import sys
inp = sys.stdin
out = sys.stdout