diff options
| author | rir <rirans@comcast.net> | 2022-05-28 23:55:04 -0400 |
|---|---|---|
| committer | rir <rirans@comcast.net> | 2022-05-28 23:55:50 -0400 |
| commit | b39b268c3ecbb98ae02f282f99a4212ac6b35fc2 (patch) | |
| tree | e506b2e78fd1bbc034f767cdcc25032fa3299378 /challenge-166/0rir | |
| parent | 8db1bb377c8e8302ae3e998e8fc674b9d45a6041 (diff) | |
| download | perlweeklychallenge-club-b39b268c3ecbb98ae02f282f99a4212ac6b35fc2.tar.gz perlweeklychallenge-club-b39b268c3ecbb98ae02f282f99a4212ac6b35fc2.tar.bz2 perlweeklychallenge-club-b39b268c3ecbb98ae02f282f99a4212ac6b35fc2.zip | |
166
Diffstat (limited to 'challenge-166/0rir')
| -rw-r--r-- | challenge-166/0rir/raku/a/m | 0 | ||||
| -rw-r--r-- | challenge-166/0rir/raku/a/n | 0 | ||||
| -rw-r--r-- | challenge-166/0rir/raku/a/q | 0 | ||||
| -rw-r--r-- | challenge-166/0rir/raku/b/n | 0 | ||||
| -rw-r--r-- | challenge-166/0rir/raku/b/o | 0 | ||||
| -rw-r--r-- | challenge-166/0rir/raku/b/ppp | 0 | ||||
| -rw-r--r-- | challenge-166/0rir/raku/b/q | 0 | ||||
| -rw-r--r-- | challenge-166/0rir/raku/b/sssss | 0 | ||||
| -rw-r--r-- | challenge-166/0rir/raku/c/o | 0 | ||||
| -rw-r--r-- | challenge-166/0rir/raku/c/q | 0 | ||||
| -rwxr-xr-x | challenge-166/0rir/raku/ch-1.raku | 71 | ||||
| -rwxr-xr-x | challenge-166/0rir/raku/ch-2.raku | 100 |
12 files changed, 171 insertions, 0 deletions
diff --git a/challenge-166/0rir/raku/a/m b/challenge-166/0rir/raku/a/m new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-166/0rir/raku/a/m diff --git a/challenge-166/0rir/raku/a/n b/challenge-166/0rir/raku/a/n new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-166/0rir/raku/a/n diff --git a/challenge-166/0rir/raku/a/q b/challenge-166/0rir/raku/a/q new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-166/0rir/raku/a/q diff --git a/challenge-166/0rir/raku/b/n b/challenge-166/0rir/raku/b/n new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-166/0rir/raku/b/n diff --git a/challenge-166/0rir/raku/b/o b/challenge-166/0rir/raku/b/o new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-166/0rir/raku/b/o diff --git a/challenge-166/0rir/raku/b/ppp b/challenge-166/0rir/raku/b/ppp new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-166/0rir/raku/b/ppp diff --git a/challenge-166/0rir/raku/b/q b/challenge-166/0rir/raku/b/q new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-166/0rir/raku/b/q diff --git a/challenge-166/0rir/raku/b/sssss b/challenge-166/0rir/raku/b/sssss new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-166/0rir/raku/b/sssss diff --git a/challenge-166/0rir/raku/c/o b/challenge-166/0rir/raku/c/o new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-166/0rir/raku/c/o diff --git a/challenge-166/0rir/raku/c/q b/challenge-166/0rir/raku/c/q new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-166/0rir/raku/c/q diff --git a/challenge-166/0rir/raku/ch-1.raku b/challenge-166/0rir/raku/ch-1.raku new file mode 100755 index 0000000000..5f244869fd --- /dev/null +++ b/challenge-166/0rir/raku/ch-1.raku @@ -0,0 +1,71 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab +use v6.d; + +constant $dictionary = $?FILE.IO.parent(5).add("data/dictionary.txt"); + +=begin comment +Task 1: Hexadecimal Words +Submitted by: Ryan J Thompson +A program that will read from a dictionary and find 2- to 8-letter words +that can be “spelled” in hexadecimal using the following letter substitutions: + o ⟶ 0 l ⟶ 1 i ⟶ 1 s ⟶ 5 t ⟶ 7 +Using the provided data/dictionary.txt. + +My extension (enabled by an 'e' option) also uses these transliterations: + nine ⟶ 9 eight⟶ 8 two ⟶ 2 too ⟶ 2 to ⟶ 2 + ate ⟶ 8 four ⟶ 4 for ⟶ 4 six ⟶ 6 +for a more 0xA519 encoding. (I don't think there be words that will use +the 'eight' but neologisms are an ill defined horde). + +=end comment + +my regex hexable { :i ^ <[olistabcdef]>**2..8 $ }; # XXX magic +my regex extended-hexable { + :i ^ <[ghnruwxolistabcdef]>**2..19 $ # XXX " +}; + +sub MAIN( Bool :$extended) { + + if $extended { + for $dictionary.words -> Str $w { + if $w ~~ /<&extended-hexable>/ { + my $word = extended-hexword-ize( $w.lc); + next unless $word.defined; + next if $word.chars > 8; # XXX magic + say $word; + } + } + }else{ + for $dictionary.words -> Str $w { + if $w ~~ / <&hexable> / { + say hexword-ize( $w.lc); + } + } + } +} + +sub hexword-ize( $word --> Str ) { + TR/listo/11570/ with $word; # XXX SPoT 11570 +} + +sub extended-hexword-ize( $word is copy --> Str ) { + for $word { + # fall through + when /eight/ { s:g/eight/8/; } + when /two/ { s:g/two/2/; } + when /too/ { s:g/too/2/; } + when /to/ { s:g/to/2/; } + when /nine/ { s:g/nine/9/; } + when /ate/ { s:g/ate/8/; } + when /fore/ { s:g/fore/4/; } + when /four/ { s:g/four/4/; } + when /for/ { s:g/for/4/; } + when /six/ { s:g/six/6/; } + } + + return Str if $word ~~ / g|h|w|n|u|r|x /; + + $word ~~ tr/listo/11570/; # XXX SPoT 11570 + $word +} diff --git a/challenge-166/0rir/raku/ch-2.raku b/challenge-166/0rir/raku/ch-2.raku new file mode 100755 index 0000000000..b0ff313c1d --- /dev/null +++ b/challenge-166/0rir/raku/ch-2.raku @@ -0,0 +1,100 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab +use v6.d; + +# TODOish: +# This presumes (1) the directories all have the same parent +# and (2) that filenames are "words". And this presumes content +# are only files and directories. + +=begin comment +Task 2: K-Directory Diff +Submitted by: Ryan J Thompson + +Given two or more directories, display a side-by-side diff-like list +of top-level items that are not in all of the directories. Display +any directory name with an appended '/'; + +Given the following directory structure: +a/: m n ppp/ q r/ +b/: n o ppp q r/ sssss +c/: o ppp/ q r/ q + +Output something like: +a | b | c +-----|-------|------ +m | | +n | n | + | o | o + | ppp | +ppp/ | | ppp/ + | sssss | +=end comment + +multi sub MAIN( Str $dir-path = '.' ) { + shallow-multi-dir-diff( $dir-path ); +} + +multi sub MAIN( *@dir-name ) { + shallow-multi-dir-diff( @dir-name); +} + +# process all top-level dirs in given directory +multi sub shallow-multi-dir-diff( Str $dir-path ) { + my @d = map *.Str, grep *.d, dir( $dir-path); + shallow-multi-dir-diff( @d ); +} + +multi sub shallow-multi-dir-diff( @dir ) { + my @header = @dir.sort; + my @width; # list for column width + my %row; # basename => count for building/ordering table + + my @path = gather for @header -> $d { take $d.IO.dir; } + @path = @path.flat[*;*]; + @path.map: { $_ = $_.d ?? ($_ ~ '/') !! $_.Str }; + + my @base = @path.sort; + @base.map: { $_ = $_.=subst: / ^ \w+ '/' /, '' }; + my @fn2dir = map { my $a = my $b = $_; + $a=.subst( / ^ \w+ '/' /, '' ); + $b=.subst( / '/' \w+ '/'? $ /, '' ); + Pair.new: $a, $b; + }, @path; + + %row = map { $_ => [ ' ', ' ', ' ' ] }, @base.unique; + + my %dir2col-num = @header.antipairs; + my %dir2flist ; + + for @fn2dir.sort -> (:key($name), :value($dir)) { + %row{$name}[%dir2col-num{$dir}] = $name; + %dir2flist{$dir}.push: $name; + } + for %dir2flist.kv -> $dir, @field { + @width[ %dir2col-num{$dir} ] «max=« map *.chars, @field; + } + for %row.kv -> $name, @field { + %row{$name} :delete if @field[0] eq @field.all; + } + _presentation( :@header, :@width, :%row); +} + +sub _presentation( :@header, :@width is copy, :%row ) { + my ( @line, @vert-sep); + + for 0 .. @width.end -> $col { + @line.push: sprintf " %-@width[$col]s ", @header[$col]; + @vert-sep.push: sprintf "%-@width[$col]s", '-' x 2 + @width[$col]; + } + say @line.join: '|'; + say @vert-sep.join: '|'; + + for %row.keys.sort -> $row { + my @diff-line; + for 0 .. @width.end -> $col { + @diff-line.push: sprintf " %-@width[$col]s ", %row{$row}[$col]; + } + say @diff-line.join: '|'; + } +} |
