Skip to main content
use colon instead of comma in title, so the 6 doesn't look like part of the score
Source Link
smls
  • 4.5k
  • 15
  • 19

Perl 6,: 921 bytes

Perl 6, 921 bytes

Perl 6: 921 bytes

Source Link
smls
  • 4.5k
  • 15
  • 19

Perl 6, 921 bytes

Translation of the Python solution.

Each program has the form say "\x<hex escape code>", except:

  • sput "\x73"

  • aput "\x61"

  • yput "\x79"

  • "\x20".say

  • "say chr 34

  • \say chr 92

  • xsay chr 120

  • 0say 1-1

  • 1say 3-2

  • 2 to 9say <n minus one>+1

For reference and ease of testing, here's the full list of programs, newline-separated.

"\x20".say
say "\x21"
say chr 34
say "\x23"
say "\x24"
say "\x25"
say "\x26"
say "\x27"
say "\x28"
say "\x29"
say "\x2A"
say "\x2B"
say "\x2C"
say "\x2D"
say "\x2E"
say "\x2F"
say 1-1
say 3-2
say 1+1
say 2+1
say 3+1
say 4+1
say 5+1
say 6+1
say 7+1
say 8+1
say "\x3A"
say "\x3B"
say "\x3C"
say "\x3D"
say "\x3E"
say "\x3F"
say "\x40"
say "\x41"
say "\x42"
say "\x43"
say "\x44"
say "\x45"
say "\x46"
say "\x47"
say "\x48"
say "\x49"
say "\x4A"
say "\x4B"
say "\x4C"
say "\x4D"
say "\x4E"
say "\x4F"
say "\x50"
say "\x51"
say "\x52"
say "\x53"
say "\x54"
say "\x55"
say "\x56"
say "\x57"
say "\x58"
say "\x59"
say "\x5A"
say "\x5B"
say chr 92
say "\x5D"
say "\x5E"
say "\x5F"
say "\x60"
put "\x61"
say "\x62"
say "\x63"
say "\x64"
say "\x65"
say "\x66"
say "\x67"
say "\x68"
say "\x69"
say "\x6A"
say "\x6B"
say "\x6C"
say "\x6D"
say "\x6E"
say "\x6F"
say "\x70"
say "\x71"
say "\x72"
put "\x73"
say "\x74"
say "\x75"
say "\x76"
say "\x77"
say chr 120
put "\x79"
say "\x7A"
say "\x7B"
say "\x7C"
say "\x7D"
say "\x7E"

Here's the code I used to test the above listing, and count the score:

#!/usr/bin/env perl6

my $file = 'print_ascii_characters.p6';

my @expected = ' ' .. '~';
my @code     = $file.IO.lines;
my $code     = @code.join: ';';
my @got      = (run 'perl6', '-e', $code, :out).out.lines.map: |*.comb;

given +@expected, +@got, +@code -> ($e, $g, $c) {
    say "WRONG COUNT: Expected $e / output $g / source $c" and exit if not $e == $g == $c;
}

for @expected Z @got -> ($e, $g) {
    say "WRONG OUTPUT: Expected {$e.perl}, got {$g.perl}" and exit if $e ne $g;
}

for @expected Z @code -> ($char, $code) {
    say "COLLISION: {$char.perl} contained in {$code.perl}" if $code.match($char);
}

say "SCORE: ", @code.map(*.chars).sum;