Skip to content

Instantly share code, notes, and snippets.

View hakank's full-sized avatar

Hakan Kjellerstrand hakank

View GitHub Profile
@hakank
hakank / apl1.md
Created June 4, 2011 05:20
My APL page

#My APL page

My APL page at http://www.hakank.org/apl/ don't show correct APL characters on some browsers. Hopefully it works better at github. Note some hour later: Now that page seems to show the chars correct.

I tend to use Dyalog APL, and it's great dfns library (also used below).

##Some APL code Note: I'm not sure how well the special APL characters are shown in every browsers. There is an APL font (APL385.ttf) downloable from Dyalog which hopefully will give good result. Here is a direct link: Apl385.ttf

For the Project Euler problems, I have used some functions (e.g. fibonacci and factors) from the dfns library mentioned above; this may - or may not - be considering cheating.

@hakank
hakank / gist:946920
Created April 28, 2011 18:15
Anagrams in a word list in K (Kona)
/
/ Here we explain a K function that shows all words in a word list
/ that are anagrams.
/
/
/ The K function used was found here:
/ http://lambda-the-ultimate.org/node/1323
/ Define the function
@hakank
hakank / gist:945167
Created April 27, 2011 20:46
Simulation of Coupon Collector's problem in K (Kona)
/ Coupon collector's problem
/ E.g. how many times is required to throw a die
/ until all 6 values has been shown.
/
/ Or: How many coupons must be bought to get the the complete collection.
/
/ http://en.wikipedia.org/wiki/Coupon_collector%27s_problem
/ Let's simulate the die version.
@hakank
hakank / gist:944913
Created April 27, 2011 18:48
SEND + MORE = MONEY in K (Kona)
/ Here are some ways of solving the SEND+MORE=MONEY puzzle
/ in K (Kona).
/ See http://en.wikipedia.org/wiki/SEND_MORE_MONEY
/
/ The first version might not be the best K way, but this
/ declarative version is the on I'm used to from
/ constraint programming etc.
/ perm defined the permutations.
@hakank
hakank / gist:944856
Created April 27, 2011 18:28
Birthday Paradox ("Surprise") in K (Kona)
/ This is a simulation of the "Birthday paradox"
/ (what I call "Birthday surprise")
/ See http://en.wikipedia.org/wiki/Birthday_problem
/ Take 20 samples of 0..364 with replacement
/ This represents the birthday of 20 persons.
20 ? 365
/ sample result
/ 195 361 24 274 145 108 157 259 51 228 330 88 180 228 86 197 121 182 336 133
@hakank
hakank / gist:944824
Created April 27, 2011 18:14
Gambler's Ruin simulation in K (Kona)
/ generate 10 random -1, 1 and
/ and count cumulative
+\ 10 ? (-1;1)
/ sample result
/ -1 0 1 0 1 2 1 2 1 2
/ just the last result:
+/x: 100 ? (-1;1)