Skip to content

Instantly share code, notes, and snippets.

@smcl
smcl / rev.j
Last active Mar 27, 2018
Reversing a string or array in J
View rev.j
NB. first attempt, took me a whole hour
sub1 =: 1 & (-~)
subtractindices =: ((# sub1) @: #)
forwardindices =: i. @: #
revindices =: (subindices - forwardindices)
revarray =: (({~) revindices)
NB. alternative implementation, I realised you could give a -ve number to "i."
revindices2 =: (i. @: - @: #)
revarray2 =: ({~) revindices2
View fizzbuzzbazz.py
#!/usr/bin/python
import sys
upto = int(sys.argv[1])
stringsForModulus = {
3: "fizz",
5: "buzz",
7: "bazz"
@smcl
smcl / dobryden.ino
Created May 23, 2017
quick demo of iso 8859-2 chars on arduino/ssd1306 using adafruit graphics library
View dobryden.ino
#include <stdint.h>
#include <gfxfont.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
char msg[32] = { // can't be bothered counting
0x44, 0x6f, 0x62, 0x72, 0xfd, 0x20, 0x64, 0x65, 0x6e, 0x2c, 0x20, 0x6a, 0x61, 0x6b, 0x20, 0x73, 0x65, 0x20, 0x6d, 0xe1, 0xb9, 0x3f,
NULL
View glcdfont.c
// Slightly updated 5x7 font for ISO8859-2
#ifndef FONT5X7_H
#define FONT5X7_H
#ifdef __AVR__
#include <avr/io.h>
#include <avr/pgmspace.h>
#elif defined(ESP8266)
#include <pgmspace.h>
@smcl
smcl / euler.fsx
Created Apr 26, 2017
some useful Project Euler functions
View euler.fsx
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()
View combination_algorithms.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View prob31.fs
(*
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 Mar 7, 2017
single-core sysbench on the thinkpad x250
View sysbench-thinkpad-x250.txt
$ 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
View prob12.fs
// 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)
View office-stares-emotions.txt
1999
amused
charmed
cheery
diverted
employed
engaged
engrossed
entertained
tickled
You can’t perform that action at this time.