Skip to content

Instantly share code, notes, and snippets.

@masak
masak / doubling.pl
Created January 6, 2013 14:55
How to double numbers left-to-right
use Test;
sub double($n) {
my @digits = $n.comb;
my @result;
my $last;
for @digits -> $d {
my $dd = $d * 2;
if $dd >= 10 {
$last++;
@masak
masak / loop-lengths.pl
Last active December 10, 2015 13:49
What's the expected loop length of a randomly chosen mapping from 1..N to 1..N?
my $MAX_N = 20;
my $TRIALS = 10_000;
for 1 .. $MAX_N -> $N {
my @lengths = loop-length(random-mapping($N)) xx $TRIALS;
my $average = ([+] @lengths) / @lengths;
my $analytical = analytical($N);
my $percent_error = abs($analytical - $average) / $analytical * 100;
FIRST say " N average analytical (error)";
@masak
masak / haskell-solution.hs
Created December 22, 2012 19:37
This is the whole Haskell code
import qualified Data.MultiSet as MultiSet
import qualified Data.Set as Set
limit :: Int
limit = 100
products :: MultiSet.MultiSet Int
products = MultiSet.fromList [ x * y | x <- [2..limit], y <- [x+1..limit-x] ]
sums_with_unambiguous_products :: Set.Set Int
@masak
masak / haskell-solution.hs
Created December 22, 2012 18:23
Problem compiling the Haskell code
import qualified Data.MultiSet as MultiSet
limit :: Int
limit = 100
products :: MultiSet.MultiSet Int
products = MultiSet.fromList [ x * y | x <- [2..limit], y <- [x+1..limit-x] ]
solutions :: [(Int, Int)]
solutions = [(4, 13)]
@masak
masak / code.hs
Created December 22, 2012 17:58
Print all pairs coming from a function -- currently prints nothing
solutions :: [(Int, Int)]
solutions = [(4, 13)]
main :: IO ()
main = mapM_ print solutions
@masak
masak / .gitconfig
Created November 27, 2012 14:26
Git colors
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = white reverse
frag = white bold
old = red bold
@masak
masak / events.list
Created November 19, 2012 15:46
The events in Adventure::Engine
Initiation phase
================
Adventure::TwoRoomsConnected
Adventure::TwoRoomsDisconnected
Adventure::DirectionAliased
Adventure::RoomMadeDark
Adventure::ThingPlaced
Adventure::ThingMadeAContainer
@masak
masak / repl.sh
Created November 19, 2012 11:03
Assignments on redeclarations are ignored in the REPL
$ nom
> my $a = 42;
42
> $a = 43
43
> my $a = 5
5
> $a
43
>
@masak
masak / synopsis.md
Created November 17, 2012 16:35
Adventure games, the eventful way

Adventure games, the eventful way

Two ways to model the world

Taking a Towers-of-Hanoi game as an example

  • Hanoi
    • Moving disks around
    • Move them all over to the other side, and you win
  • Move them away again, and you un-win
@masak
masak / discussion.txt
Created November 5, 2012 16:43
discussion on #scheme
17:19 < mark_weaver> masak: In Scheme, a single macro invocation can expand into several procedures. furthermore, a macro can
expand into another macro use, which later expands into something different. in general, macro expansion
can split up and combine pieces of code into a very different arrangement. the lexical contours can only
be determined after macro expansion.
17:20 < LeoNerd> Ooooh.. that's another good point
17:21 < mark_weaver> masak: therefore, it seems to me that you're very much on the wrong track.
17:21 < masak> interesting. I will try to process this.
17:21 < mark_weaver> I suggest that you read some papers on hygienic macros. let me dig up some references.
17:21 < LeoNerd> Yah; I'm still with "macros are sort of like rewrites of the source code" in CPP-style.. only nicer
17:21 < masak> mark_weaver: excellent. that was my next question :)