diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-11-28 15:54:41 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-28 15:54:41 +0000 |
| commit | f0a67deb08318b9b405f269c0c152b0c0ea0372a (patch) | |
| tree | 70d91521de0be445cc4dbbb0f883033a0999b7a9 | |
| parent | c080faf96278bc39241afc30f80454b56345bd8c (diff) | |
| parent | dd801bdf0a4e1e7b991192eeb30d5a8c9ddf60c4 (diff) | |
| download | perlweeklychallenge-club-f0a67deb08318b9b405f269c0c152b0c0ea0372a.tar.gz perlweeklychallenge-club-f0a67deb08318b9b405f269c0c152b0c0ea0372a.tar.bz2 perlweeklychallenge-club-f0a67deb08318b9b405f269c0c152b0c0ea0372a.zip | |
Merge pull request #7176 from steve-g-lynn/branch-for-challenge-193
pwc 193
| -rw-r--r-- | challenge-193/steve-g-lynn/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-193/steve-g-lynn/julia/ch-1.sh | 4 | ||||
| -rwxr-xr-x | challenge-193/steve-g-lynn/perl/ch-1.sh | 4 | ||||
| -rwxr-xr-x | challenge-193/steve-g-lynn/perl/ch-2.pl | 60 | ||||
| -rwxr-xr-x | challenge-193/steve-g-lynn/raku/ch-1.sh | 4 | ||||
| -rwxr-xr-x | challenge-193/steve-g-lynn/raku/ch-2.p6 | 45 |
6 files changed, 118 insertions, 0 deletions
diff --git a/challenge-193/steve-g-lynn/blog.txt b/challenge-193/steve-g-lynn/blog.txt new file mode 100644 index 0000000000..3f17c82427 --- /dev/null +++ b/challenge-193/steve-g-lynn/blog.txt @@ -0,0 +1 @@ +https://thiujiac.blogspot.com/2022/11/pwc-193.html diff --git a/challenge-193/steve-g-lynn/julia/ch-1.sh b/challenge-193/steve-g-lynn/julia/ch-1.sh new file mode 100755 index 0000000000..e509f7c40e --- /dev/null +++ b/challenge-193/steve-g-lynn/julia/ch-1.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +julia -e 'using Printf;for i in (parse(Int64,"0b"*repeat("0",parse(Int64,ARGS[1]))):parse(Int64,"0b"*repeat("1",parse(Int64,ARGS[1])))); println(SubString(bitstring(i),65-parse(Int64,ARGS[1]))); end;' $@ + diff --git a/challenge-193/steve-g-lynn/perl/ch-1.sh b/challenge-193/steve-g-lynn/perl/ch-1.sh new file mode 100755 index 0000000000..7a4ae72bee --- /dev/null +++ b/challenge-193/steve-g-lynn/perl/ch-1.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +perl -e 'for (eval ("0b".(0 x $ARGV[0]). ".." . "0b". (1 x $ARGV[0]))){printf("%b\n",$_)}' $@ + diff --git a/challenge-193/steve-g-lynn/perl/ch-2.pl b/challenge-193/steve-g-lynn/perl/ch-2.pl new file mode 100755 index 0000000000..a8b817dd77 --- /dev/null +++ b/challenge-193/steve-g-lynn/perl/ch-2.pl @@ -0,0 +1,60 @@ +#!/usr/bin/env perl + +#-- restricted to perl 4 syntax + +{ +local %code_hash; +map { $code_hash{('a' .. 'z')[$_]} = $_+1} (0 .. 25); + +local *odd_string = sub { + + #-- helper sub-subroutines + + local *difference_array = sub { + local ($s)=@_; + local $retval; + local @s=split(//,$s); + map { + $retval .= ($code_hash{$s[$_]} - $code_hash{$s[$_-1]}) . ":"; + } + (1 .. @s-1); + chop $retval; + return $retval; + }; + + local *difference_array_loop = sub { + local ($ctr,@retval); + for $ctr (0..@s-1) { + $retval[$ctr]=&difference_array( $s[$ctr] ); + } + return @retval; + }; + + local *mybag = sub { + local (@s)=@_; + local %retval; + + foreach (@s) { + $retval{$_}++; + } + return %retval; + }; + + + #-- root sub + local (@s)=@_; + + local @difference_array_loop = &difference_array_loop; + local %mybag = &mybag(@difference_array_loop); + + for (0 .. @difference_array_loop-1) { + return $s[$_] if $mybag{$difference_array_loop[$_]}==1; + } + +}; + +print &odd_string("adc","wzy","abc"),"\n"; +print &odd_string("aaa","bob","ccc","ddd"),"\n"; + +} + diff --git a/challenge-193/steve-g-lynn/raku/ch-1.sh b/challenge-193/steve-g-lynn/raku/ch-1.sh new file mode 100755 index 0000000000..4311c44463 --- /dev/null +++ b/challenge-193/steve-g-lynn/raku/ch-1.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +raku -e 'use MONKEY-SEE-NO-EVAL; for (EVAL("0b" ~ (0 x @*ARGS[0]) ~ ".." ~ "0b" ~ (1 x @*ARGS[0]))) {printf("%b\n",Int($_))}' $@ + diff --git a/challenge-193/steve-g-lynn/raku/ch-2.p6 b/challenge-193/steve-g-lynn/raku/ch-2.p6 new file mode 100755 index 0000000000..c4d112b465 --- /dev/null +++ b/challenge-193/steve-g-lynn/raku/ch-2.p6 @@ -0,0 +1,45 @@ +#!/usr/bin/env perl6 + +our %code-hash; +(0 .. 25).map( {%code-hash{ ('a' .. 'z')[$_]} = (1 .. 26)[$_]} ); + +#-- not bothering with input validation and exception handling +#-- assume input is conformable list of strings of same length +#-- with exactly one string with the wrong difference array + +say &odd-string(["adc","wzy","abc"]); #(1,1) +say &odd-string(["aaa","bob","ccc","ddd"]); #(13,-13) + +multi sub difference-array( Str $s ) { + (1 .. $s.chars-1).map({%code-hash{$s.comb[$_]}-%code-hash{$s.comb[$_-1]}}); +} + +multi sub difference-array( @s ) { +#returns array of difference arrays +#as well as hash linking each string to its difference array + my (@retval,%retval); + for (@s) -> $s { + my @difference-array=&difference-array($s); + push @retval, @difference-array; + %retval{@difference-array.raku} = $s; + } + (@retval,%retval); +} + +sub my-bag( @difference-array ) { #-- input is array of arrays + my %retval=(); + for (@difference-array) -> @s { + %retval{@s.raku}++; + } + %retval; +} + +multi sub odd-string( %my-bag ) { #-- input is custom bag + %my-bag.keys.grep({%my-bag{$_}==1}); +} + +multi sub odd-string( @s ) { + my @difference-array=&difference-array(@s); + @difference-array[1]{(&odd-string(&my-bag(@difference-array[0])))}; +} + |
