Skip to content

Instantly share code, notes, and snippets.

@smcl
smcl / euler.fsx
Created April 26, 2017 09:30
some useful Project Euler functions
let pair_multiply s1 s2 =
[ for x in s1 do
for y in s2 do
yield (x,y) ]
let enumerate (a:'a[]) =
Array.mapi (fun i x -> (i,x)) a
let pandigital (n:int) =
let a = string(n).ToCharArray()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@smcl
smcl / prob31.fs
Last active April 14, 2017 18:02
(*
Problem 31 - Coin sums
----------------------
In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
It is possible to make £2 in the following way:
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
How many different ways can £2 be made using any number of coins?
*)
@smcl
smcl / sysbench-thinkpad-x250.txt
Created March 7, 2017 22:00
single-core sysbench on the thinkpad x250
$ sysbench --num-threads=1 --test=cpu --cpu-max-prime=20000 --validate run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Additional request validation enabled.
Doing CPU performance benchmark
// attempt 2 - use recursion, threading the index and current triangle number to each call
// less memory intensive, shouldn't be too terrible on stack (tail recursion)
// but the "countFactors" function sticks out as a little nasty
//
// run in f# jupyter notebook, or using mono (fsharpc prob12.fs && mono prob12.exe)
let minFactors = 5
// let minFactors = 500
let isFactor x y = (x % y = 0UL)
1999
amused
charmed
cheery
diverted
employed
engaged
engrossed
entertained
tickled
"""
ipy.py
This is a fairly nastily hacked together piece of code to produce a visualisation of the execution
of a simple python application IronPython. It uses PIL to produce a series of PNG files in a
directory ./out which each have a listing of instructions, stack, globals and output for the
ipy vm.
"""
@smcl
smcl / test.py.txt
Created December 25, 2016 16:15
A quick dump of the instructions IronPython executes for test.py @ https://gist.github.com/smcl/18ebd10afd7d12ba897285bf03207a1d - the main logic in the file itself is in the frame executed between lines 195343 and 195384 (each "- " indicates a new frame)
This file has been truncated, but you can view the full file.
InitParameter()
InitParameter()
InitParameter()
InitParameter()
LoadLocal()
LoadCached(0)
TypeEquals()()
LoadCached(1)
Call(Boolean InterpretedCallSiteTest(Boolean, System.Object))
BranchFalse(16)
@smcl
smcl / test.py
Created December 25, 2016 16:11
x = 10
y = 20
z = x + y
print z
@smcl
smcl / interesting.cs
Created December 18, 2016 21:18
weird snippet i saw in ironpython - they pre-allocate an cache of 1100 ints-as-objects in an array (in range -100..+10000) and avoid a number of int->object cast by returning the cached version. weird
/// <summary>
/// Gets a singleton boxed value for the given integer if possible, otherwise boxes the integer.
/// </summary>
/// <param name="value">The value to box.</param>
/// <returns>The boxed value.</returns>
public static object Int32ToObject(Int32 value) {
// caches improves pystone by ~5-10% on MS .Net 1.1, this is a very integer intense app
// TODO: investigate if this still helps perf. There's evidence that it's harmful on
// .NET 3.5 and 4.0