aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2021-07-19 09:15:57 +1000
committerSimon Green <mail@simon.green>2021-07-19 09:15:57 +1000
commitdb1d93d57d41919aa77e70cfe4a5683217b127bd (patch)
treefa7d70afbef0a8f531366832414f13eb063b1b9c
parent1aa7b6eaba2a58fc1ef0612373e3aed6b61f345d (diff)
downloadperlweeklychallenge-club-db1d93d57d41919aa77e70cfe4a5683217b127bd.tar.gz
perlweeklychallenge-club-db1d93d57d41919aa77e70cfe4a5683217b127bd.tar.bz2
perlweeklychallenge-club-db1d93d57d41919aa77e70cfe4a5683217b127bd.zip
sgreen solution to challenge 121, task 1
-rw-r--r--challenge-121/sgreen/README.md4
-rwxr-xr-xchallenge-121/sgreen/perl/ch-1.pl20
2 files changed, 22 insertions, 2 deletions
diff --git a/challenge-121/sgreen/README.md b/challenge-121/sgreen/README.md
index 55a06d2776..4476447d18 100644
--- a/challenge-121/sgreen/README.md
+++ b/challenge-121/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 120
+# The Weekly Challenge 121
-Solution by Simon Green. [Blog](https://dev.to/simongreennet/weekly-challenge-120-3o3i)
+Solution by Simon Green.
diff --git a/challenge-121/sgreen/perl/ch-1.pl b/challenge-121/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..2f07d6fe37
--- /dev/null
+++ b/challenge-121/sgreen/perl/ch-1.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+sub main {
+ my ( $number, $bit ) = @_;
+
+ # Sanity check
+ die "You must specify two values\n" unless defined $number and defined $bit;
+ die "The first value doesn't appear to be a positive integer\n" unless $number =~ /^[1-9][0-9]*$/;
+ die "The first value has to be less than 256\n" unless $number < 256;
+ die "The second value needs to be between 1 and 8\n" unless $bit =~ /^[1-8]/;
+
+ # Flip the nth bit from the right
+ say $number ^ 2**( $bit - 1 );
+}
+
+main(@ARGV);