Skip to content

Instantly share code, notes, and snippets.

View .vimrc
set noautoindent
set expandtab
set shiftwidth=4
set tabstop=4
from types import ModuleType
import sys
class LazyModule(ModuleType):
def __init__(self, name, doc, source):
super().__init__(name, doc)
self.__source = source
self.__loaded = None
import attr
def solve(initial_assignments, restriction_function):
Given variables 0...n, such that variable i is allowed to
take on values in initial_assignments[i], find an assignment
of those variables which satisfies the restrictions enforced
by `restriction_function`. Return this as a list of assigned
values of length n.

StS boss notes

These are what I think of as the "primary strategies" for the bosses. All of these can be killed in other ways, but these are the main things I'm thinking about.

NB I'm not actually that good at the game. Some of this is regurgitated from people who are better than me, some are my own thoughts, all errors are mine.

Act 1


import attr
from random import randint
class World:
potatoes = attr.ib(default=0)
orcs = attr.ib(default=0)
destiny = attr.ib(default=0)

How to pick a number

One decision we often find ourselves having to make is that we have to put a number on something.

For example:

  • How much should I pay for e.g. a computer/car/house?
  • How much time per week should I spend e.g. cleaning/reading/working?
  • How long do I expect this task to take?
  • Roughly how large is this unknown quantity? e.g. how many people would be interested in a product, how large should a company be, how many boxes do I need to move?
View ishouldknow
#!/usr/bin/env python
from datetime import date
import calendar
if __name__ == '__main__':
today =
if == 1:
day = "1st"
import numpy.random as npr
# Monte Carlo simulation code to estimate the probability that I had COVID
# back in February 2020. My flatmate had COVID almost certainly (he still doesn't
# have his sense of smell back and also got a positive antibody test about
# 6 months later). I had more ambiguous symptoms but was ill with something
# COVID like at the same time. How likely was it that I had COVID vs something
# unrelated?
# Please note that I am not a specialist in disease transmission and it is
A module for when you find modern numeric notation far too convenient to use
and want to go back to good old fashioned roman numerals.
You can import any numeral you like from here and it will work just fine.
>>> from numerals import IX, XVIIIII

Finding the shortlex predecessor

Problem: You have a DFA M and a string s that matches it. You want to find the shortlex-predecessor to s in the language matched by the DFA.


Create the P which matches all strings that are strictly shortlex smaller than s. Build the product DFA M' which intersects M with P, matching all strings matched by M that are shortlex predecessors of s.

Now annotate each state in M' with the length of the longest matching string starting from there (this is possible because there is an upper bound on the length of strings matched by M' and is easy to calculate recursively with dynamic programming because this means there are no loops in the DFA).