Code Snippets Raku

Short texts Raku 🧑‍💻 Code snippets Raku ✍️ Reading lists Raku 👀

Thundergnat

use NativeCall; use SDL2::Raw; my int ($w, $h) = 320, 240; SDL_Init(VIDEO); my SDL_Window $window = SDL_CreateWindow( “White Noise – Raku”, SDL_WINDOWPOS_CENTERED_MASK, SDL_WINDOWPOS_CENTERED_MASK, $w, $h, RESIZABLE ); my SDL_Renderer $renderer = SDL_CreateRenderer( $window, -1, ACCELERATED +| TARGETTEXTURE ); my $noise_texture = SDL_CreateTexture($renderer, %PIXELFORMAT, STREAMING, $w, $h); my $pixdatabuf = CArray[int64].new(0, $w, $h, $w); sub render […]

compute_this.raku

#!/usr/bin/env raku sub postfix:( Int $n ) { [*] (1..$n) } sub prefix:( *@nums ) { [+] @nums } sub compute_this (Int $n) { Σ (0..$n).map( -> $r { $n! / ($r! * ($n – $r)!) } ) } say compute_this(9); say compute_this(10); say compute_this(11);

69226857a.pl

sub decode_utf8 { my ($s) = @_; utf8::decode($s) or die(“Invalid Input”); return $s; } my $in = “\x61\xC3\x8B\x00\xC3\xBF”; my $out = join “”, substr($in, 0, 3), decode_utf8(substr($in, 3, 1)), decode_utf8(substr($in, 4, 2)); open(my $fh, ‘>:raw’, $ARGV[0]) or die $!; print($fh $out); __END__ $ od -t x1 out 0000000 61 c3 8b 00 ff 0000005

69226857b.pl

sub encode_utf8 { my ($s) = @_; utf8::encode($s); $s } my $in = “\x61\xC3\x8B\x00\xC3\xBF”; utf8::decode($in) or die(“Invalid Input”); my $out = join “”, encode_utf8(substr($in, 0, 2)), substr($in, 2, 1), substr($in, 3, 1); open(my $fh, ‘>:raw’, $ARGV[0]) or die $!; print($fh $out); __END__ $ od -t x1 out 0000000 61 c3 8b 00 ff 0000005

Perl 6 Solutions for code-golf.io

# NOTE: EACH SOLUTION IS SELF CONTAINED. # This file can’t be run as a script because the trailing semi-colon is left off of each solution. # Divisors {(1…$_).grep($_%%*).put}for 1…Ⅽ # Emirp Numbers $_≠.flip&&($_,.flip)».is-prime.all&&.say for ^Ⅿ # Evil Numbers .base(2).comb(~1)%2||.say for ^Ⅼ # Fibonacci (0,1,*+*…*)[^㉛]».say # Fizz Buzz say (“Fizz”if $_%%3)~(“Buzz”if $_%%5)||$_ for 1…Ⅽ # […]