Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
perlweeklychallenge-club/challenge-084/colin-crain/raku/ch-1.raku
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (36 sloc)
1.14 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
# | |
# | |
# reverse-and-repeat.raku | |
# | |
# TASK #1 › Reverse Integer | |
# Submitted by: Mohammad S Anwar | |
# You are given an integer $N. | |
# | |
# Write a script to reverse the given integer and print the result. | |
# Print 0 if the result doesn’t fit in 32-bit signed integer. | |
# | |
# The number 2,147,483,647 is the maximum positive value for a 32-bit | |
# signed binary integer in computing. | |
# | |
# Example 1: | |
# Input: 1234 | |
# Output: 4321 | |
# Example 2: | |
# Input: -1234 | |
# Output: -4321 | |
# Example 3: | |
# Input: 1231230512 | |
# Output: 0 | |
# | |
# 2020 colin crain | |
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## | |
# unit sub MAIN (Int $num where $num > 0 = 1729) ; | |
# | |
# say $num.flip +> 31 > 0 ?? 0 | |
# !! $num.flip; | |
unit sub MAIN (Int $num = -1700) ; | |
my $sign = $num < 0 ?? -1 !! 1 ; | |
my $out = $sign * $num.abs.flip ; | |
say -2147483648 <= $out <= 2147483647 ?? $out | |
!! 0; | |