Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Oates MattOates

View GitHub Profile
View day2_task2.pl6
#!/usr/bin/env perl6
sub character_differences(Str $str1, Str $str2) {
$str1.comb Z~~ $str2.comb
}
sub hamming_distance(Str $str1, Str $str2) {
my @differences = character_differences($str1, $str2);
return @differences.grep(* == False).elems;
}
View index.html
Time: <span id="clockDisplay"></span>
@MattOates
MattOates / main.p6
Created Oct 16, 2018
6pad gist test
View main.p6
say "Ohai!";
for ^10 -> $stuff {
say $stuff if $stuff.is-prime;
}
View hackerrank_bench.p6
use Stats;
sub bench($name, &code) {
my ($start,$end);
my @times;
for 1..100 {
$start = now;
code();
@MattOates
MattOates / mandelbrot.p6
Last active Aug 13, 2018
Quick and dirty script for plotting the Mandelbrot set in the terminal using unicode shading characters. An example invocation: perl6 mandelbrot.p6 --mid-x=-0.73e0 --mid-y=0.246e0 --zoom=0.03e0 --height=300
View mandelbrot.p6
use Terminal::Width;
sub is-mandelbrot(Complex $z0, int $max=100) {
my Complex $z = $z0;
for ^$max -> $n {
return $n if ($z.abs() > 2e0);
$z = $z**2 + $z0;
}
return $max;
}
View build_chromosome_files.p6
#!/usr/bin/env perl6
use Compress::Zlib;
use IO::String;
my $DATA_DIR = %*ENV<DATA_DIR> // '/Users/matt/data/reference/GRCh37/sequence/dna';
for dir($DATA_DIR).grep(/chr\d+\.fa\.gz/) -> $file {
my $out_file = $file.IO.extension('txt', :2parts).open(:w);
my $chromosome = IO::String.new(buffer=>gzslurp($file));
for $chromosome.lines -> $line {
View build_chromosome_files.p6
#!/usr/bin/env perl6
use Compress::Zlib;
use IO::String;
my $DATA_DIR = %*ENV<DATA_DIR> // '/Users/matt/data/reference/GRCh37/sequence/dna';
for dir($DATA_DIR).grep(/chr\d+\.fa\.gz/) -> $file {
my $out_file = $file.IO.extension('txt', :2parts).open(:w);
my $chromosome = IO::String.new(buffer=>gzslurp($file));
for $chromosome.lines -> $line {
View build_chromosome_files.p6
#!/usr/bin/env perl6
use Compress::Zlib;
use IO::String;
my $DATA_DIR = %*ENV<DATA_DIR> // '/Users/matt/data/reference/GRCh37/sequence/dna';
for dir($DATA_DIR).grep(/chr\d+\.fa\.gz/) -> $file {
my $out_file = $file.IO.extension('txt', :2parts).open(:w);
my $chromosome = IO::String.new(buffer=>gzslurp($file));
for $chromosome.lines -> $line {
View gist:3bb818947552ed3917eb3739fdd02c12
1) every time you don't use sigils you are hogging namespace for something thats not variables. Something close to keywords like
"from" and "to" is a bad plan. I've seen several people including myself use "from $i to $j by $inc" as their own range/list constructing
syntax. I have no idea if Rakudo is smart enough to negotiate sigiless variables and keywords at the same time, Id almost hope its not!
2) to some extent it doesn't matter if the OP finds it easier to read or if you do, almost the entirety of code you will come
across will not use that convention. So learning that way to start out with is only going to cause pain working with others. Just wanting
to write a debug statement for that whats the simple plan? say "from {from} to {to}" not so clean given the norm for the language... You're
changing *semantics* for the sake of visual aesthetic not readability. Your intent is less clear given the language, its less readable but
perhaps prettier.
3) friendlier for the OP to learn a language which isn
View annual-rate.p6
#!/usr/bin/env perl6
use v6;
use Stats;
#Quick benchmark script for https://www.reddit.com/r/perl6/comments/8tdfvz/handwavy_speed_test/
# $ perl6 annual-rate.p6 --upto=100
# annual-rate-with-helper: ran in 0.0551038961038961 seconds (σ = 0.015335042908917152 seconds)
# Result was 1.3232569411493311
# annual-rate-rat-exp: ran in 0.7545948945615983 seconds (σ = 0.03632803218476478 seconds)
# Result was 1.3232569411482977