diff options
121 files changed, 8181 insertions, 3095 deletions
diff --git a/challenge-002/shasank-shah/README b/challenge-002/shasank-shah/README new file mode 100644 index 0000000000..3d2d911c6e --- /dev/null +++ b/challenge-002/shasank-shah/README @@ -0,0 +1 @@ +Solution by Shasank Shah diff --git a/challenge-002/shasank-shah/perl/ch-1.pl b/challenge-002/shasank-shah/perl/ch-1.pl new file mode 100644 index 0000000000..e9223cac3b --- /dev/null +++ b/challenge-002/shasank-shah/perl/ch-1.pl @@ -0,0 +1,17 @@ +#! /usr/bin/perl +use v5.22; +say 'Casting with addition'; +print 'Number? '; +say 0 + <>; + +say 'Regex substitution'; +print 'Number? '; +say <> =~ s/^0*(\d+)$/$1/r; + +say 'Explicit integer casting'; +print 'Number? '; +say int <>; + +say 'Using map and a flip flop'; +print 'Number? '; +say join '', map { /[^0]/ .. /\n/ ? $_ : () } split //, <>; diff --git a/challenge-002/shasank-shah/perl/ch-2.pl b/challenge-002/shasank-shah/perl/ch-2.pl new file mode 100644 index 0000000000..1d67909982 --- /dev/null +++ b/challenge-002/shasank-shah/perl/ch-2.pl @@ -0,0 +1,46 @@ +#! /usr/bin/perl +use v5.22; +my @to_table = ( 0 .. 9, 'A' .. 'Y'); +my %from_table; +while (my ($index, $element) = each @to_table) { + $from_table{$element} = $index; +} + +sub convert_to { + my $x = shift; my $pow = 1; my @ret; + do { + my $digit = $x % 35; + unshift @ret, $to_table[$digit]; + $x -= $digit; + $x /= 35; + } while $x > 0; + return join '', @ret +} + +sub convert_from { + my $x; my $pow =1; + for (reverse split //, shift) { + $x += $from_table{$_} * $pow; + $pow *= 35; + } + return $x +} + +my $command = shift; +if ($command eq 'to') { + my $arg = shift; + die 'Need a number to convert' unless $arg; + die 'Improper base10 number' unless $arg =~ /^\d+$/; + say convert_to($arg) +} elsif ($command eq 'from') { + my $arg = shift; + die 'Need a number to convert' unless $arg; + die 'Improper base35 number' unless $arg =~ /^[0-9A-Y]+$/; + say convert_from($arg) +} else { + say <<"EOF" + USAGE: $0 [ to | from ] + to - will convert a base10 number to base35 + from - will convert a base35 number to base10 +EOF +} diff --git a/challenge-009/feng-chang/README b/challenge-009/feng-chang/README new file mode 100644 index 0000000000..74e56de3ed --- /dev |
