Skip to content

Instantly share code, notes, and snippets.

sub view ($file='todo.org') {
my $todo=open "/home/echo/Dropbox/todo/$file";
my @lines= $todo.lines;
$todo.close;
say " there are "~ +@lines ~ " tasks";
my $order=1;
for @lines -> $line {
say "$order"~"."~"$line";
$order++;
multi MAIN('a'){ view ; add ;}
multi MAIN('v'){ view ;}
multi MAIN('d'){ done ;}
multi MAIN('vd'){ viewdone;}
sub MAIN ($op="v"){ #$op="v" eqv $op='v'
my %All = v=>&view, a=>&add, d =>&done, vd=&viewdone;
%All{$op}();
}
@swuecho
swuecho / sqrt_10000.pl
Created August 3, 2012 21:55
after motiz
my Int $i = 2 * 10 ** 20_002;
my Int $sqrt = 10 ** 10_001;
my Int $next_sqrt = ($i div $sqrt + $sqrt) div 2;
repeat {
$sqrt = $next_sqrt;
$next_sqrt = ($i div $sqrt + $sqrt) div 2;
} until $sqrt == $next_sqrt;
@swuecho
swuecho / Min_stack.pl
Created August 4, 2012 19:02
Min Stack
class Minstack {
has @.stack;
has @.min;
method mpush($item) {
push @.stack, $item;
if @.min==0 or @.min[*-1] > $item {
push @.min, $item;
class Minstack {
has @.stack;
has @.min;
method mpush($item) {
push @.stack, $item;
if @.min==0 or @.min[*-1] > $item {
push @.min, $item;
#todo how to use multi?
class Minstack {
has @.stack;
has @.min;
method mpush($item) {
push @.stack, $item;
if @.min==0 or @.min[*-1] > $item {
#todo how to use multi?
class Minstack {
has @!stack;
has @!min;
method mpush($item) {
push @.stack, $item;
if @.min==0 or @.min[*-1] > $item {
class Minstack {
has @.stack;
has @.min;
}
multi push(Minstack $mstack, $item) {
push $mstack.stack, $item;
if $mstack.min==0 or $mstack.min[*-1] > $item {
push $mstack.min, $item;
sub deci_bin($n) {
return $n if $n==0 || $n==1;
my $k = $n div 2;
my $b = $n % 2;
my $E = deci_bin($k);
return $E~$b;
}
sub automata($rule,$row) {