Skip to content

Instantly share code, notes, and snippets.

@zeimusu
zeimusu / isqrt.go
Created December 30, 2022 23:26
Calculate integer square root and base 2 log
package main
import (
"fmt"
)
func Iblog(n uint) uint {
i := uint(0)
for n > 1 {
n = n / 2
@zeimusu
zeimusu / exoplanets.csv
Last active April 7, 2022 15:37
named exoplanets and their standard names
Identification Proper name
14 Andromedae b Spe
18 Delphini b Arion
41 Lyncis b Arkas
42 Draconis b Orbitar
47 Ursae Majoris b Taphao Thong
47 Ursae Majoris c Taphao Kaew
51 Pegasi b Dimidium
55 Cancri b Galileo
55 Cancri c Brahe
\documentclass[12pt,a4paper]{exam}
\pointsmarginright
\begin{document}
\begin{questions}
\question
\part[2]
Show that $371 \times 83 = 30\,793$
\part[1]
Write down the answer to $3.71 \times 0.83$
@zeimusu
zeimusu / league.py
Last active September 11, 2016 21:04
Produce a league table from a list of match results.
"""
Module that processes a list of results, and produces a sorted league table.
The list of results is a pandas data frame with format
"Home" "Home Score" "Away" "Away Score"
0 "Chelsea" 4 "Man U" 2
1 ... ... ... ...
Result is a Data frame representing the league table
@zeimusu
zeimusu / kepler.py
Created March 29, 2016 17:24
Models orbits using keplers equations, then tries to makes sounds from them.
import math
#import sys
#import sunau
#import array
"""
ecc=0.5
P=1
p=1
if len(sys.argv)>1:
ecc=float(sys.argv[1])
@zeimusu
zeimusu / Fleishman.py
Last active June 26, 2023 08:03
Generate data with given mean, standard deviation, skew, and kurtosis. Intended for monte carlo simulations with non normal distributions
import numpy as np
from numpy.linalg import solve
import logging
logging.basicConfig(level = logging.DEBUG)
from scipy.stats import moment,norm
def fleishman(b, c, d):
"""calculate the variance, skew and kurtois of a Fleishman distribution
F = -c + bZ + cZ^2 + dZ^3, where Z ~ N(0,1)
"""
@zeimusu
zeimusu / mollweide.py
Last active August 28, 2017 02:14
The mollweide equal area map projection. Convert longitude and latitude to and from 2d, flat cartiesian coordinates
#!/usr/bin/env python3
from math import sin, cos, pi, sqrt, asin, log
sqrt2 = sqrt(2)
def solveNR(lat, epsilon=1e-6):
"""Solve the equation $2\theta\sin(2\theta)=\pi\sin(\mathrm{lat})$
using Newtons method"""
if abs(lat) == pi / 2:
@zeimusu
zeimusu / tictactoe.py
Created February 1, 2016 21:08
A game of noughts and crosses,
#!/usr/bin/env python3
"""Usage:
tictactoe : Play the graphical game
tictactoe t(ext) : play the text game, using the keypad
"""
import logging as log
import random, sys
import tkinter as tk
log.basicConfig(level=log.WARNING)
@zeimusu
zeimusu / LoveCalculator.py
Last active December 17, 2015 20:47
Use a numeralogical technique known to teens from the '80s to predict the love percentage from names
#!/usr/bin/env python3
#Use: LoveCalculator.py "Katy Perry" "Justin Bieber"
import sys
import itertools
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = itertools.tee(iterable)
next(b, None)
return zip(a, b)
@zeimusu
zeimusu / stronghold.py
Last active August 29, 2015 14:23
Find a Minecraft stronghold
#Find a minecraft stronghold
#To find a stronghold you need an eye of ender, which you throw into the air.
#Make a note of your current location and the direction in which the eye goes.
#You can find these from the F3 debug screen.
#Move to a second point (it should be reasonably distant from the first)
#Throw the eye again and note the second point and direction. Enter
#the numbers below and run. It outputs the location of the stronghold.