aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-10-26 10:02:50 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2021-10-26 10:02:50 +0100
commit688502e2cac619b639d6bf4a57ebd10986cfaf66 (patch)
tree17213a741398cd9ca7514f068f0a3c70b15e9bd4
parent4fbb301ccb5620c8bcee20462bd1bb8145b0d13c (diff)
downloadperlweeklychallenge-club-688502e2cac619b639d6bf4a57ebd10986cfaf66.tar.gz
perlweeklychallenge-club-688502e2cac619b639d6bf4a57ebd10986cfaf66.tar.bz2
perlweeklychallenge-club-688502e2cac619b639d6bf4a57ebd10986cfaf66.zip
Tools
-rw-r--r--challenge-001/paulo-custodio/go.pl15
-rw-r--r--challenge-001/paulo-custodio/stats.pl61
-rw-r--r--challenge-001/paulo-custodio/untabify.pl30
3 files changed, 106 insertions, 0 deletions
diff --git a/challenge-001/paulo-custodio/go.pl b/challenge-001/paulo-custodio/go.pl
new file mode 100644
index 0000000000..97670bc755
--- /dev/null
+++ b/challenge-001/paulo-custodio/go.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+
+use Modern::Perl;
+use Path::Tiny;
+
+@ARGV==1 && $ARGV[0]=~/^\d+$/ && $ARGV[0]>0
+ or die "Usage: ",path($0)->basename," nr\n";
+my $nr = sprintf("%03d", $ARGV[0]);
+
+for my $dir (qw( ada awk basic c cpp d forth lua perl python t )) {
+ path("challenge-$nr/paulo-custodio/$dir")->mkpath;
+}
+path("challenge-$nr/paulo-custodio/README")->spew("Solution by Paulo Custodio\n");
+chdir("challenge-$nr/paulo-custodio");
+system("bash");
diff --git a/challenge-001/paulo-custodio/stats.pl b/challenge-001/paulo-custodio/stats.pl
new file mode 100644
index 0000000000..1cb928a96a
--- /dev/null
+++ b/challenge-001/paulo-custodio/stats.pl
@@ -0,0 +1,61 @@
+#!/usr/bin/env perl
+
+# show stats of challenge submissions
+
+use Modern::Perl;
+use Path::Tiny;
+
+my $USER = "paulo-custodio";
+
+our %LANG = (
+ ada => 'adb',
+ awk => 'awk',
+ basic => 'bas',
+ bc => 'bc',
+ c => 'c',
+ cpp => 'cpp',
+ d => 'd',
+ forth => 'fs',
+ lua => 'lua',
+ perl => 'pl',
+ python => 'py',
+);
+
+# collect data
+my @sols;
+for my $chall_dir (path(".")->children(qr/challenge-\d+/)) {
+ my($chall) = $chall_dir =~ /(\d+)/ or die;
+ $chall += 0;
+
+ for my $lang (sort keys %LANG) {
+ my $dir = path($chall_dir, $USER, $lang);
+ next unless $dir->is_dir;
+
+ my $sols = scalar($dir->children(qr/^ch[-_]\d\.$LANG{$lang}$/));
+
+ $sols[$chall]{$lang} = $sols;
+ }
+}
+
+# output
+for my $chall (1 .. $#sols) {
+ if (($chall) % 10 == 1) {
+ say "-" x 80;
+ print " " x 4;
+ for my $lang (sort keys %LANG) {
+ print " ", $lang;
+ }
+ say "";
+ say "-" x 80;
+ }
+
+ printf("%3d ", $chall);
+ for my $lang (sort keys %LANG) {
+ my $width = length($lang);
+ my $before = int(($width-1)/2);
+ my $after = $width - 1 - $before;
+ my $value = $sols[$chall]{$lang} || " ";
+ print " ", " " x $before, $value, " " x $after;
+ }
+ say "";
+}
diff --git a/challenge-001/paulo-custodio/untabify.pl b/challenge-001/paulo-custodio/untabify.pl
new file mode 100644
index 0000000000..9f3c5657d4
--- /dev/null
+++ b/challenge-001/paulo-custodio/untabify.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+
+# convert my code from 4-tabs to spaces
+
+use Modern::Perl;
+use Path::Tiny;
+use Text::Tabs; $Text::Tabs::tabstop = 4;
+
+for my $dir (<challenge-*/paulo-custodio>) {
+ my $iter = path($dir)->iterator({recurse=>1});
+ while (defined(my $path = $iter->())) {
+ next unless $path->is_file;
+ next if $path =~ /~$/; # temp files
+ my $ext = ""; $path->basename =~ /(\.\w+)$/ and $ext = $1;
+ next if $ext eq "" || $ext =~ /\.(exe|o|obj|ali|ads)$/; # binaries
+ untabify($path);
+ }
+}
+
+sub untabify {
+ my($file) = @_;
+ my $text = path($file)->slurp_raw;
+ my @lines = expand(map {s/\s+$//r} split(/\n/, $text));
+ my $new_text = join "\n", (@lines, "");
+ if ($text ne $new_text) {
+ path($file)->copy("$file~");
+ say "Formatting $file";
+ path($file)->spew_raw($new_text);
+ }
+}