Skip to content

Solution submission weekly challenge (#2) #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions challenge-002/ozzy/README
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
Solution by Ozzy

------------
Challenge 1:
------------
The simplest solution I could think of was conversion of a numeric (integer) string through
the use of the built-in Int method:

my $a = "004" # Example string representing positive integer with leading zeros
my $b = $a.Int # Convert string to Int using built-in method Int, and so strip zeros
say $b # Print the Int; OUTPUT: 4

In a Perl6/Bash one-liner, this would look something like this:

perl6 -pe '$_=.Int' <<< 004

but this, in itself, isn't very practical since Bash can do it with even less fuzz:

a="004"
echo ${a##+(0)}

------------
Challenge 2:
------------
The obvious way to go is probably the use of Perl6' .base and .parse-base methods:

loop {

my Str $a = prompt("\nPlease, give me a decimal (base-10) number : ");
say("$a in decimal notation is { $a.Int.base(35) } in base-35 notation.");

$a = prompt("\nNow give me a base-35 number [A-Y0-9]: ");
say("$a in base-35 notation is { $a.parse-base(35) } in base-10 notation.")

}