aboutsummaryrefslogtreecommitdiff
path: root/challenge-002
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-01-25 20:07:40 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-01-26 00:06:54 +0000
commit3fa58628535d4041c7cc648c005080ca88f18c18 (patch)
tree336fe3cc14f518f05e871ab974cc86a09a2fd8f6 /challenge-002
parent3d3900a2f0f69c54a34683e4e1b5da007b4af9d9 (diff)
downloadperlweeklychallenge-club-3fa58628535d4041c7cc648c005080ca88f18c18.tar.gz
perlweeklychallenge-club-3fa58628535d4041c7cc648c005080ca88f18c18.tar.bz2
perlweeklychallenge-club-3fa58628535d4041c7cc648c005080ca88f18c18.zip
Replace tabs by spaces so that indentation looks correct
Diffstat (limited to 'challenge-002')
-rw-r--r--challenge-002/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-002/paulo-custodio/perl/ch-2.pl56
-rw-r--r--challenge-002/paulo-custodio/test.pl34
3 files changed, 46 insertions, 46 deletions
diff --git a/challenge-002/paulo-custodio/perl/ch-1.pl b/challenge-002/paulo-custodio/perl/ch-1.pl
index cbe49c0da7..154ae4402e 100644
--- a/challenge-002/paulo-custodio/perl/ch-1.pl
+++ b/challenge-002/paulo-custodio/perl/ch-1.pl
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# Challenge 002
-#
+#
# Challenge #1
# Write a script or one-liner to remove leading zeros from positive numbers.
diff --git a/challenge-002/paulo-custodio/perl/ch-2.pl b/challenge-002/paulo-custodio/perl/ch-2.pl
index db37e40e4c..ea000b6ffd 100644
--- a/challenge-002/paulo-custodio/perl/ch-2.pl
+++ b/challenge-002/paulo-custodio/perl/ch-2.pl
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# Challenge 002
-#
+#
# Challenge #2
# Write a script that can convert integers to and from a base35 representation, using the characters 0-9 and A-Y. Dave Jacoby came up with nice description about base35, in case you needed some background.
@@ -15,41 +15,41 @@ my @digits = ('0'..'9','A'..'Z');
our $opt_r;
(getopts('r') && @ARGV==1) or die "Usage: ch-2.pl [-r] number\n";
if ($opt_r) {
- say scan_base($ARGV[0], 35);
+ say scan_base($ARGV[0], 35);
}
else {
- say print_base($ARGV[0], 35);
+ say print_base($ARGV[0], 35);
}
sub print_base {
- my($n, $base) = @_;
- my $negative = ($n < 0);
- $n = abs($n);
- my $output = '';
- do {
- my $d = $n % $base;
- $n = int($n / $base);
- $output = $digits[$d].$output;
- } while ($n > 0);
- $output = "-".$output if $negative;
- return $output;
+ my($n, $base) = @_;
+ my $negative = ($n < 0);
+ $n = abs($n);
+ my $output = '';
+ do {
+ my $d = $n % $base;
+ $n = int($n / $base);
+ $output = $digits[$d].$output;
+ } while ($n > 0);
+ $output = "-".$output if $negative;
+ return $output;
}
sub scan_base {
- my($str, $base) = @_;
- my $n = 0;
- my $negative;
- $negative = 1 if $str =~ s/^-//;
- while ($str =~ s/^(\w)//) {
- my $c = $1;
- my $d = ($c =~ /\d/) ? 0+$c : ord(uc($c))-ord('A')+10;
- $d < $base or die "cannot parse $c$str\n";
- $n = $base * $n + $d;
- }
- $str eq '' or die "cannot parse $str\n";
- $n = -$n if $negative;
- return $n;
+ my($str, $base) = @_;
+ my $n = 0;
+ my $negative;
+ $negative = 1 if $str =~ s/^-//;
+ while ($str =~ s/^(\w)//) {
+ my $c = $1;
+ my $d = ($c =~ /\d/) ? 0+$c : ord(uc($c))-ord('A')+10;
+ $d < $base or die "cannot parse $c$str\n";
+ $n = $base * $n + $d;
+ }
+ $str eq '' or die "cannot parse $str\n";
+ $n = -$n if $negative;
+ return $n;
}
- \ No newline at end of file
+
diff --git a/challenge-002/paulo-custodio/test.pl b/challenge-002/paulo-custodio/test.pl
index c322545716..e3ca75b1c3 100644
--- a/challenge-002/paulo-custodio/test.pl
+++ b/challenge-002/paulo-custodio/test.pl
@@ -6,27 +6,27 @@ use Test::More;
use 5.030;
is capture("perl perl/ch-1.pl 000123"), "123\n";
-is capture("perl perl/ch-1.pl 123"), "123\n";
+is capture("perl perl/ch-1.pl 123"), "123\n";
-is capture("perl perl/ch-2.pl 0"), "0\n";
-is capture("perl perl/ch-2.pl 1"), "1\n";
-is capture("perl perl/ch-2.pl 10"), "A\n";
-is capture("perl perl/ch-2.pl 34"), "Y\n";
-is capture("perl perl/ch-2.pl 35"), "10\n";
-is capture("perl perl/ch-2.pl -- -35"), "-10\n";
+is capture("perl perl/ch-2.pl 0"), "0\n";
+is capture("perl perl/ch-2.pl 1"), "1\n";
+is capture("perl perl/ch-2.pl 10"), "A\n";
+is capture("perl perl/ch-2.pl 34"), "Y\n";
+is capture("perl perl/ch-2.pl 35"), "10\n";
+is capture("perl perl/ch-2.pl -- -35"), "-10\n";
-is capture("perl perl/ch-2.pl -r 0"), "0\n";
-is capture("perl perl/ch-2.pl -r 1"), "1\n";
-is capture("perl perl/ch-2.pl -r A"), "10\n";
-is capture("perl perl/ch-2.pl -r Y"), "34\n";
-is capture("perl perl/ch-2.pl -r 10"), "35\n";
-is capture("perl perl/ch-2.pl -r -- -10"), "-35\n";
+is capture("perl perl/ch-2.pl -r 0"), "0\n";
+is capture("perl perl/ch-2.pl -r 1"), "1\n";
+is capture("perl perl/ch-2.pl -r A"), "10\n";
+is capture("perl perl/ch-2.pl -r Y"), "34\n";
+is capture("perl perl/ch-2.pl -r 10"), "35\n";
+is capture("perl perl/ch-2.pl -r -- -10"), "-35\n";
done_testing;
sub capture {
- my($cmd) = @_;
- my $out = `$cmd`;
- $out =~ s/[ \t\v\f\r]*\n/\n/g;
- return $out;
+ my($cmd) = @_;
+ my $out = `$cmd`;
+ $out =~ s/[ \t\v\f\r]*\n/\n/g;
+ return $out;
}