Skip to content

Instantly share code, notes, and snippets.

C:\Users\grond>panda install Readline
==> Readline depends on LibraryCheck
==> Fetching LibraryCheck
==> Building LibraryCheck
==> Testing LibraryCheck
no such file or directory
in sub run-and-gather-output at C:\rakudo\share\perl6\site\sources\5AEF9DA5AE15E5AB5CB2ADB58A455E007FA7839E line 85
in block at C:\rakudo\share\perl6\site\sources\FB10E7A100D50F6DB505EC4DC538BEAB5154DED3 line 22
in sub indir at C:\rakudo\share\perl6\site\sources\5AEF9DA5AE15E5AB5CB2ADB58A455E007FA7839E line 20
in method test at C:\rakudo\share\perl6\site\sources\FB10E7A100D50F6DB505EC4DC538BEAB5154DED3 line 5
@grondilu
grondilu / permutations.p6
Last active December 14, 2015 21:32
permutations with NQP code
use nqp;
sub permutations(int $n where $n > 0) {
Seq.new:
class :: does Iterator {
# See: L<https://en.wikipedia.org/wiki/Permutation#Generationn_lexicographic_order>
has int $!n;
has Mu $!permutation;
submethod BUILD(:$n) { $!n = $n; $!permutation := nqp::list(); self }
#method is-lazy { True }
method pull-one {
@grondilu
grondilu / day7.p6
Last active December 10, 2015 17:24
draft for day7 of adventofcode.com
grammar circuit {
rule TOP { <wiring>+ }
rule wiring { <expression> '->' <destination=identifier> }
rule expression { <NOT> | <AND> | <OR> | <RSHIFT> | <LSHIFT> | <value> }
token value { <literal> | <identifier> }
token literal { <.digit>+ }
token identifier { <.alpha>+ }
rule NOT { NOT <value> }
rule AND { <left=value> AND <right=value> }
rule OR { <left=value> OR <right=value> }
@grondilu
grondilu / permutations.p6
Last active December 9, 2015 19:54
an other attempt at improving permutations, using the third method in http://rosettacode.org/wiki/Permutations#Perl_6
sub permutations(int $n) {
Seq.new:
class :: does Iterator {
has int $!n;
submethod BUILD { $!n = $n; self }
method pull-one {
return (^$!n).List unless (state $i = 0)++;
return IterationEnd if $i >= self.count-only;
return map { |(state @ = ^$!n).splice($_, 1) }, $i.polymod($!n ... 2);
}
@grondilu
grondilu / input.txt
Created December 9, 2015 08:50
my input for day3 of advent of code
>^^v^<>v<<<v<v^>>v^^^<v<>^^><^<<^vv>>>^<<^>><vv<<v^<^^><>>><>v<><>^^<^^^<><>>vv>vv>v<<^>v<>^>v<v^<>v>><>^v<<<<v^vv^><v>v^>>>vv>v^^^<^^<>>v<^^v<>^<vv^^<^><<>^>><^<>>><><vv><>v<<<><><>v><<>^^^^v>>^>^<v<<vv^^<v<^<^>^^v^^^^^v<><^v><<><^v^>v<<>^<>^^v^<>v<v^>v>^^<vv^v><^<>^v<><^><v^><><><<<<>^vv^>^vvvvv><><^<vv^v^v>v<<^<^^v^<>^<vv><v<v^v<<v<<^^>>^^^v^>v<><^vv<<^<>v<v><><v^^><v<>^^>^^>v^>^<<<<v><v<<>v><^v>^>><v^^<^>v<vvvv<>>>>>^v^^>v<v<^<vv>^>^vv^>vv^^v<<^<^^<>v>vv^v>><>>>v^>^>^^v<>^<v<<>^vv>v^<<v>v<<><v>^vvv<v<vvv^v<vv<v^^^>v><<^<>><v^^>^v^>>^v<^<><v<>>v^<>>v<>>v^^^><^>>vvvv>^v<^><<>>^<>^>vv><v<<>>^^>v^^^><^<<^^v>v<^<<>v>^^vvv^v^>v^<>^^<>v^v>v>v<v^>vv>^^v<>v>>^<>><>v>v^<<vvvv<vvv><v^<^>^v<>>^><v>><>^<v>v<v>vv^>>vvv<>v>v<v^>>^>>v<<>^<>^<>>>^v<<<^<^v>vv^>><<><v^>^v^^^v<>^^vv><>><>>^>v^<v<>v<>>^<<^v>^^^<>^v^><>v<<v>vv^>vv<<>>><<^v^<>v<vv>>>^^<>^><<^>vv>>^<<v^^vv<>>><v>v><^<v<<>>>^^<>>^<^v><>vv^^^v>vvv>^><<>^^>^<<v^<v<^v<<>vvv<^<<>^>^v<vv<^>vvv>v>vv^<v^><>>^vv<^^^vv><^vv<v^<><v^vvv><<^>^^><v<<vv^>v<vv<v>^<>^v<<>v<v^v^>
@grondilu
grondilu / day3.pl
Last active December 9, 2015 08:54
advent of code day 3 fail in perl
use strict;
use warnings;
use feature qw<say>;
my @directions = split //, <DATA>;
my ($i, $j) = (0, 0);
my %houses = ("0:0" => 1);
for (@directions) {
next unless /[><^v]/;
@grondilu
grondilu / exp-by-squaring.p6
Created November 29, 2015 03:53
trying to implement exponentiation by squaring efficiently on perl 6
# https://en.wikipedia.org/wiki/Exponentiation_by_squaring
sub exp-by-squaring-iterative(Numeric $x is copy, int $n is copy) {
return 1 if $n == 0;
if $n < 0 {
$x = 1 / $x;
$n = -$n;
}
my $y = 1;
while $n > 1 {
$y = $y * $x if $n +& 1;
@grondilu
grondilu / permutations.p6
Last active November 20, 2015 09:12
generate all permutations with the lexicographic method
# See: L<https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order>
use nqp;
sub permutations(int $n) {
Seq.new(
class :: does Iterator {
has int $!n;
has @!a;
submethod BUILD(:$n) { $!n = $n; self }
#method is-lazy { True }
@grondilu
grondilu / permutations.p6
Last active November 15, 2015 06:26
faster permutations for Perl 6
sub permutations(int $n) {
my int $i;
$n == 1 ?? ( (0,), ) !!
gather {
my @permutations = permutations($n - 1);
while $i < $n {
my Int @i;
my int $j;
@i.push($j++) while $j < $i;
$j = $i + 1;
@grondilu
grondilu / triangle.html
Last active August 29, 2015 14:24
very minimalist WebGL program
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="gl-matrix-min.js"></script>
<script>
function webGLStart() {
var shader_sources = {
fragment : [