Skip to content

Instantly share code, notes, and snippets.

View christianp's full-sized avatar

Christian Lawson-Perfect christianp

View GitHub Profile
@christianp
christianp / fractions.exam
Created June 8, 2011 21:12
fraction numbers in answer question
{
name: Fractions test
questions: [
{
name: Question 4
variables: {
a: "sa*random(1..9)"
b: "sb*random(1..9)"
c: "sc*random(1..9)"
@christianp
christianp / testA.exam
Created June 15, 2011 15:10
a demo exam for Numbas
{
name: TestA
extensions: [jsxgraph]
questions: [
{
name: Question 1
variables: {
a: random(1..11)
g: "switch(a=1, random(2..11),a=2,random(3..11#2),a=3,random(4,5,7,8,10,11),a=4,random(5,7,9,11),a=5, random(6,7,8,9,11),a=6,random(7,11),a=7,random(8,9,10,11),a=8,random(9,11),a=9,random(10,11),a=10,11,a=11,12)"
b: "switch(f=2,1,f=3,random(1,2),f=4,random(1,3),f=5, random(1..4),f=6,random(1,5),f=7,random(1..6),f=8,random(1,3,5,7),f=9,random(1,2,4,5,7,8),f=10,random(1,3,7,9),f=11,random(1..10))"
@christianp
christianp / testcom.exam
Created August 16, 2011 11:12 — forked from BillFoster/gist:1143713
Complex numbers and display/simplification
{
name: testcom
questions: [
{
name: Complex Test
statement: """Express the following in the form $a+bi$ where $a$ and $b$ are real. """
variables: {
a4: "s4*random(1..9)"
b4: "s1*random(1..9)"
@christianp
christianp / mcqmarks.exam
Created October 13, 2011 09:43
Multiple choice question with more than one mark for a choice
{
name: "Demo Exam"
duration: 0
percentPass: 50
shuffleQuestions: false
navigation: {
reverse: false
browse: false
showfrontpage: false
onadvance: {
@christianp
christianp / flip.py
Created December 19, 2011 17:52
Flipping squares puzzle
from itertools import product
from operator import mul
from functools import reduce
from math import log
#represent the state of the board with a binary string of 9 digits
#the states form a group under XOR on each cell -
#when combining states S1 and S2, a cell is lit up iff it is lit up in S1 XOR it is lit up in S2
#states commute: S1.S2 = S2.S1, because XOR commutes
#additionally, note that for every state S, S.S = 0.
@christianp
christianp / lev.gv
Created January 9, 2012 16:44
Graph of minimal edit distance between residents of PHD2
graph PHD2 {
ratio=0.55;fontname="Calibri";fontsize=24;label="PHD2";size="5.374,4.5";margin=0;
node [shape=none,fontname="Calibri",fontsize=20];
"Stacey Aston";
"Nathan Barker";
"Matthew Buckley";
"David Elliott";
"Michael Garrett";
"Christian Perfect";
@christianp
christianp / primepermutations.py
Created January 11, 2012 10:49
Find three-digit primes where any reordering of the digits is still prime.
#generate a list of primes, somewhat inefficiently
primes=[2]
for x in range(3,999,2):
if len([y for y in primes if y*y<=x and x % y == 0])==0:
primes.append(x)
#keep only three-digit primes
primes = [x for x in primes if x>100]
#collect primes into anagram classes
@christianp
christianp / gist:1638930
Created January 19, 2012 09:21
lambda-ish PEG
/*
* Classic example grammar, which recognizes simple arithmetic expressions like
* "2*(3+4)". The parser generated from this grammar then computes their value.
*/
start
= expr:expression { return expr({}); }
expression
= function
/*
In Javascript, any function acts as an object constructor when you call it with the `new` keyword.
So, this:
var spring1 = new Spring(particle1, particle2, length, stiffness);
creates a new object which inherits all of Spring.prototype's methods and properties, and then the function Spring(..) is called on it.
Inside the function Spring(..), `this` refers to the newly-created object.
*/
@christianp
christianp / madabel.py
Created February 22, 2012 10:13
A python3 version of the game Mad Abel
from itertools import product,combinations,count
from random import shuffle,randrange
from time import sleep
def nicelist(l):
if len(l)<=1:
return ''.join(l)
else:
return ', '.join(l[:-1])+' and '+l[-1]