Skip to content

Instantly share code, notes, and snippets.

View VienosNotes's full-sized avatar

D.Aoki VienosNotes

View GitHub Profile
use v6;
class Path {
has Str $!path;
method new (Str $str) {
my Str $path;
use v6;
class Growl {
has Str $.app_name;
method new (Str $app_name = "Perl6 Growl Library") {
self.bless(*, app_name => $app_name);
}
@VienosNotes
VienosNotes / dice1.pl
Created August 24, 2011 17:00
mD6 + nD10 in Perl6 (1)
use v6;
sub mD6 {
gather { take 6.rand.Int + 1 for 0..* }
}
sub nD10 {
gather { take 10.rand.Int for 0..* }
}
@VienosNotes
VienosNotes / dice2.pl
Created August 24, 2011 17:45
mD6 + nD10 in Perl6 (2)
use v6;
multi sub infix:<D> ($lhs, $rhs) {
my $sum = 0;
$sum += $rhs.rand.Int for 1..$lhs;
return $sum;
}
multi sub infix:<D> ($lhs, $rhs where {$_ == 6} ) {
return &infix:<D>.candidates[0]($lhs, $rhs) + $lhs;
@VienosNotes
VienosNotes / Mandelbrot.pl
Created November 9, 2011 19:10
Mandelbrot with Perl6
use v6;
class Bitmap {
has IO $!file;
has %!header;
has $!w_count;
has $!h_count;
has $!remainder;
has $!template;
@VienosNotes
VienosNotes / split.pl
Created November 16, 2011 05:21
Image spliter
use strict;
use warnings;
use Imager;
mkdir "numbers";
mkdir "modified";
mkdir "concat";
for (@ARGV) {
chop for 1..4;
use v6;
class T {
has $.with_accessor;
has $!without_accessor;
method new ($i as Int) {
self.bless(*, with_accessor => $i, without_accessor => $i);
}
@VienosNotes
VienosNotes / CA.pl
Created December 15, 2011 06:25
1-Dimentional Cellular Automaton
use v6;
class CA {
has @.data;
has @.rule;
method new ($rule, $length, $population) {
my @data = (1 xx $population, 0 xx $length - $population).pick(*);
my @rule = $rule.fmt("%08b").flip.comb.map({.Int});
self.bless(*, data => @data, rule => @rule);
@VienosNotes
VienosNotes / lisp.pl
Created December 26, 2011 17:06
Lisp subset implementation in Perl6 Grammar and Action
# This version is very old!
# Latest code is here ↓
# https://github.com/VienosNotes/Domino/blob/master/domino.pl
use v6;
grammar Lisp {
token left { '(' };
token right { ')' };
token num { \d+ }
@VienosNotes
VienosNotes / mapBetween.pl
Created January 5, 2012 09:01
mapBetween
use v6;
sub mapBetween ($op, *@list) {
(@list Z @list[1..*]).map({ $op($^a,$^b) });
}
my @list = 1,2,3,4,5;
say mapBetween(&infix:<+>, @list);
say mapBetween(&infix:<+>, 1,2,3,4,5);
# 3 5 7 9