diff options
| author | Abigail <abigail@abigail.be> | 2021-03-02 16:02:05 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-03-02 16:05:34 +0100 |
| commit | 243aa4b8f70cd83388fab9bd2ae88d01f0047411 (patch) | |
| tree | 791e2e0f3b92e2f9e50c76f3040ee98988d27fab /challenge-102/abigail | |
| parent | 1994e57f605a17e8eb0a1a19987ce6215d18f017 (diff) | |
| download | perlweeklychallenge-club-243aa4b8f70cd83388fab9bd2ae88d01f0047411.tar.gz perlweeklychallenge-club-243aa4b8f70cd83388fab9bd2ae88d01f0047411.tar.bz2 perlweeklychallenge-club-243aa4b8f70cd83388fab9bd2ae88d01f0047411.zip | |
List of rare numbers to preprocess.
We grabbed the list of known rare numbers (https://oeis.org/A035519/b035519.txt)
and wrote a preprocessing script which takes those numbers, buckets
them on their length, and writes out code in 8 different languages
so we have the buckets (as strings) available in an array.
Diffstat (limited to 'challenge-102/abigail')
| -rwxr-xr-x | challenge-102/abigail/data/preprocess | 126 | ||||
| -rw-r--r-- | challenge-102/abigail/data/rare_numbers.txt | 124 |
2 files changed, 250 insertions, 0 deletions
diff --git a/challenge-102/abigail/data/preprocess b/challenge-102/abigail/data/preprocess new file mode 100755 index 0000000000..28a195f0fe --- /dev/null +++ b/challenge-102/abigail/data/preprocess @@ -0,0 +1,126 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +open my $fh, "<", "rare_numbers.txt" or die "open rare_numbers.txt: $!"; + +my @buckets; + +while (my $rn = <$fh>) { + chomp $rn; + $rn =~ s/^[0-9]+\s+//; + push @{$buckets [length $rn]} => $rn; +} + +my @bs = sort {$a <=> $b} grep {$buckets [$_]} keys @buckets; + + +open my $awk_h, ">", "rn.awk" or die "open rn.awk: $!"; +open my $bash_h, ">", "rn.sh" or die "open rn.sh: $!"; +open my $c_h, ">", "rn.c" or die "open rn.c: $!"; +open my $lua_h, ">", "rn.lua" or die "open rn.lua: $!"; +open my $node_h, ">", "rn.js" or die "open rn.js: $!"; +open my $perl_h, ">", "rn.pl" or die "open rn.pl: $!"; +open my $python_h, ">", "rn.py" or die "open rn.py: $!"; +open my $ruby_h, ">", "rn.rb" or die "open rn.rb: $!"; + +say $awk_h "BEGIN {"; +say $bash_h "declare -a rare_numbers\n"; +say $c_h "char * rare_numbers [23];\n"; +say $c_h "int main () {"; +say $lua_h "rare_numbers = {}\n"; +say $node_h "let rare_numbers = []\n"; +say $perl_h "my \@rare_numbers;\n"; +say $python_h "rare_numbers = {}\n"; +say $ruby_h "rare_numbers = Array . new"; + +foreach my $bs (0 .. 22) { + if (!$buckets [$bs]) { + printf $c_h " rare_numbers [%2d] = NULL;\n" + => $bs; + next; + } + + # + # AWK + # + printf $awk_h ' rare_numbers [%2d] = ', $bs; + print $awk_h join " \\\n " => + map {sprintf "%26s", qq {"$_\\n"}} @{$buckets [$bs]}; + print $awk_h "\n"; + + # + # Bash + # + printf $bash_h 'rare_numbers[%2d]=', $bs; + print $bash_h join "\\\n" => + map {qq {"$_\\n"}} @{$buckets [$bs]}; + print $bash_h "\n"; + + # + # C + # + printf $c_h ' rare_numbers [%2d] = ', $bs; + print $c_h join " \\\n " => + map {sprintf "%26s", qq {"$_\\n"}} @{$buckets [$bs]}; + print $c_h ";\n"; + + # + # Lua + # + printf $lua_h "rare_numbers [%2d] = ", $bs; + print $lua_h join " ..\n " => + map {sprintf "%26s", qq {"$_\\n"}} @{$buckets [$bs]}; + print $lua_h "\n"; + + # + # Node.js + # + printf $node_h "rare_numbers [%2d] = ", $bs; + print $node_h join " +\n " => + map {sprintf "%26s", qq {"$_\\n"}} @{$buckets [$bs]}; + print $node_h "\n"; + + # + # Perl + # + printf $perl_h '$rare_numbers [%2d] = ', $bs; + print $perl_h join " .\n " => + map {sprintf "%26s", qq {"$_\\n"}} @{$buckets [$bs]}; + say $perl_h ";"; + + # + # Python + # + printf $python_h "rare_numbers [%4s] =", "'$bs'"; + print $python_h join " +\\\n " => + map {sprintf "%26s", qq {"$_\\n"}} @{$buckets [$bs]}; + print $python_h "\n"; + + # + # Ruby + # + printf $ruby_h "rare_numbers [%2s] =", $bs; + print $ruby_h join " +\n " => + map {sprintf "%26s", qq {"$_\\n"}} @{$buckets [$bs]}; + print $ruby_h "\n"; +} +say $awk_h "}"; +say $c_h "}"; + + +close $awk_h or die "close rn.awk: $!"; +close $bash_h or die "close rn.sh: $!"; +close $c_h or die "close rn.n: $!"; +close $lua_h or die "close rn.lua: $!"; +close $node_h or die "close rn.js: $!"; +close $perl_h or die "close rn.pl: $!"; +close $python_h or die "close rn.py: $!"; +close $ruby_h or die "close rn.rb: $!"; diff --git a/challenge-102/abigail/data/rare_numbers.txt b/challenge-102/abigail/data/rare_numbers.txt new file mode 100644 index 0000000000..31ec71d11b --- /dev/null +++ b/challenge-102/abigail/data/rare_numbers.txt @@ -0,0 +1,124 @@ +1 65 +2 621770 +3 281089082 +4 2022652202 +5 2042832002 +6 868591084757 +7 872546974178 +8 872568754178 +9 6979302951885 +10 20313693904202 +11 20313839704202 +12 20331657922202 +13 20331875722202 +14 20333875702202 +15 40313893704200 +16 40351893720200 +17 200142385731002 +18 204238494066002 +19 221462345754122 +20 244062891224042 +21 245518996076442 +22 248359494187442 +23 403058392434500 +24 441054594034340 +25 816984566129618 +26 2078311262161202 +27 2133786945766212 +28 2135568943984212 +29 2135764587964212 +30 2135786765764212 +31 4135786945764210 +32 6157577986646405 +33 6889765708183410 +34 8052956026592517 +35 8052956206592517 +36 8191154686620818 +37 8191156864620818 +38 8191376864400818 +39 8650327689541457 +40 8650349867341457 +41 22542040692914522 +42 67725910561765640 +43 86965750494756968 +44 225342456863243522 +45 225342458663243522 +46 225342478643243522 +47 284684666566486482 +48 284684868364486482 +49 297128548234950692 +50 297128722852950692 +51 297148324656930692 +52 297148546434930692 +53 497168548234910690 +54 619431353040136925 +55 619631153042134925 +56 631688638047992345 +57 633288858025996145 +58 633488632647994145 +59 653488856225994125 +60 811865096390477018 +61 865721270017296468 +62 871975098681469178 +63 898907259301737498 +64 2042401829204402402 +65 2060303819041450202 +66 2420424089100600242 +67 2551755006254571552 +68 2702373360882732072 +69 2825378427312735282 +70 6531727101458000045 +71 6988066446726832640 +72 8066308349502036608 +73 8197906905009010818 +74 8200756128308135597 +75 8320411466598809138 +76 22134434735752443122 +77 22134434753752443122 +78 22134436953532443122 +79 22136414517954423122 +80 22136414971554423122 +81 22136456771730423122 +82 61952807156239928885 +83 61999171315484316965 +84 65459144877856561700 +85 208393425242000083802 +86 219518549668074815912 +87 257661195832219326752 +88 286694688797362186682 +89 837982875780054779738 +90 2414924301133245383042 +91 2414924323311045383042 +92 2414946523311023183042 +93 2576494891793995836752 +94 2576494893971995836752 +95 2620937863931054483162 +96 2620937863931054483162 +97 2620955641393276283162 +98 2622935621573476481162 +99 2622935643751276481162 +100 2622937641933274481162 +101 2622955841933256281162 +102 2622957843751254281162 +103 2727651947516658327272 +104 2747736918335953517072 +105 2788047668617596408872 +106 2788047848617776408872 +107 2788047868437576408872 +108 2788047888617376408872 +109 2939501759705522349392 +110 2939503375709360349392 +111 2939503537707740349392 +112 2939521359525562149392 +113 2939521557527542149392 +114 2939523577527340149392 +115 2939523779525320149392 +116 2959503377707360349192 +117 6344828989519887483525 +118 8045841652464561594308 +119 8045841654642561594308 +120 8655059576513659814468 +121 8655059772157639814468 +122 8655079374155679614468 +123 8655079574515659614468 +124 8888070771864228883913 |
