Skip to content

Instantly share code, notes, and snippets.

@masak
masak / lista.md
Last active December 15, 2015 13:49
Rekommenderade ölsorter till jonalv

Det blev en del. Jag har fetlagt de två du måste prova.

IPA (India Pale Ale)

Min första typ av öl som jag gillade. Mycket humle och högre alkoholhalt än vanlig pale ale; bägge i syfte att kunna skeppas från Storbrittanien till Indien.

Övrig ale

@masak
masak / Z4-and-Z2_X_Z2.pl
Last active December 15, 2015 13:18
Groups of order four
class Group {
has Str $.name;
has Int $.elems;
has &.rule;
method map(&xform) {
(^$.elems).map(&xform);
}
method times(Int $l, Int $r) {
@masak
masak / Rules.pm
Last active December 15, 2015 09:19
An idea for a web based Perl 6 implementation of Nomic
enum State <Ongoing Finished>;
enum Role <Voter Proposer>;
enum Choice <Nay Aye>;
enum Result <Lost Won>;
class Vote is rw {
has @.registered_votes;
has State $.state;
has Result $.result;
@masak
masak / tree-adt-using-classes.pl
Last active December 15, 2015 05:59
Perl 6 can do ADTs, using classes. Kind of.
# data Tree a = Branch (Tree a) (Tree a) | Leaf a
class Tree { ... }
class Tree::Branch {
has Tree $.left;
has Tree $.right;
}
class Tree::Leaf {
@masak
masak / tree-adt.pl
Last active December 15, 2015 05:59
Yes, Perl 6 can do ADTs. Sort of.
# data Tree a = Branch (Tree a) (Tree a) | Leaf a
subset Tree of Hash where &is_branch | &is_leaf;
sub is_branch($_) {
.keys == 2
&& .exists('left')
&& .<left> ~~ Tree
&& .exists('right')
&& .<right> ~~ Tree
@masak
masak / 01-bruce
Last active December 15, 2015 01:39
Bruce's email about his t1 solution
Carl,
First, I want to thank you for reviewing all of the code and running the contest. That is a lot of work and it must have taken many hours through unfamiliar and strange code. Some of my code (especially the first problem) was likely the hardest to read and longest as well.
I am not asking you to take any action. I would just like to summarize the logic because I believe the algorithm is O(n) and not exponential.
========= Deciding who is a knight and who is a knave
There are two types of actions, declaring and comparing:
Declarations:
@masak
masak / balanced-bracket.p6
Last active May 11, 2018 07:45
Uniformly selecting a balanced-bracket string of lengh n
# Recursive definition: a balanced-bracket string is always empty or of the form
#
# [S1]S2
#
# where S1 and S2 are balanced-bracket strings.
#
# Let n(S) be the number of bracket pairs in the balanced-bracket string S. And let
# C(n) be the number of balanced-bracket strings with exactly n bracket pairs.
# C(n) happens to be the Catalan sequence <http://oeis.org/A000108>:
#
@masak
masak / closure.pl
Created March 9, 2013 16:21
From a starting seed and a bunch of operations, generate the closure
sub closure($elem, *@ops) {
my $set = set $elem;
my @queue = $elem;
while @queue {
my $e = pop @queue;
for @ops.map(-> &op { &op($e)}) -> $d {
next if $d (elem) $set;
$set = $set (|) $d;
push @queue, $d;
}
@masak
masak / month.pl
Last active December 14, 2015 14:08
A Perl 6 script to write out the days of each month with weekday, month-day and month name. Defaulting to
#! /usr/local/bin/nom
constant last-month = Date.today.delta(-1, month);
sub MAIN($year = last-month.year, $month = last-month.month) {
my @weekdays = < _ Mån Tis Ons Tors Fre Lör Sön> X~ 'dag';
my @months = < _
januari februari mars april
maj juni juli augusti
september oktober november december