From 2dbeaa8b6609f83fa270a4da2ebbfabd85da3e8e Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Fri, 2 Jul 2021 10:03:05 -0500 Subject: Add files via upload --- challenge-119/paul-fajman/ch-1.pl | 36 ++++++++++++++++++++++++++++ challenge-119/paul-fajman/ch-2.pl | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 challenge-119/paul-fajman/ch-1.pl create mode 100644 challenge-119/paul-fajman/ch-2.pl diff --git a/challenge-119/paul-fajman/ch-1.pl b/challenge-119/paul-fajman/ch-1.pl new file mode 100644 index 0000000000..03918969c3 --- /dev/null +++ b/challenge-119/paul-fajman/ch-1.pl @@ -0,0 +1,36 @@ +#/usr/bin/perl + +use strict; +use warnings; + +use POSIX; + +my $int = $ARGV[0]; +my $quo = $int; +my ($i, $rem); +my $total = 0; +my @nibbles=(); + +# Calculate binary number +while($quo ne 0) { + $rem = floor($quo % 2); + unshift @nibbles, $rem; + $quo = floor($quo/2); +} + +# Check that final number is 8 digits +while ($#nibbles+1 lt 8) { + unshift @nibbles, 0; +} + +# Swap the nibbles +my @final = splice(@nibbles, 4); +@final = (@final, @nibbles); + +# Calcuate the new decimal number +for ($i=7; $i>-1; $i--) { + $total+= $final[$i]*(2**(7-$i)); +} + +print "Input: \$N = $int\n"; +print "Output: $total\n"; diff --git a/challenge-119/paul-fajman/ch-2.pl b/challenge-119/paul-fajman/ch-2.pl new file mode 100644 index 0000000000..06299baa92 --- /dev/null +++ b/challenge-119/paul-fajman/ch-2.pl @@ -0,0 +1,49 @@ +#/usr/bin/perl + +use strict; +use warnings; + +use POSIX; + +my $input = $ARGV[0]; +my @numbers; + +my ($quo, $rem, $i); +my $check=0; +my ($oneone, $output); + +for ($i=1;$i<$input+1;$i++) { + $quo = $i; + # Calculate base 4 number + # Later throw out any values with 0 + while ($quo ne 0) { + $rem = floor($quo % 4); + unshift @numbers, $rem; + $quo = floor($quo/4); + } + # Check for any digit with a 0 + foreach (@numbers) { + if ($_ eq 0) { + $check=1; + next; + } + $oneone.=$_; + } + + # Check if any digits are consecutive ones or if one was a 0; + if ($oneone =~ m/11/ || $check eq 1) { + undef($oneone); + undef(@numbers); + $check = 0; + $input++; + next; + } + + $output = $oneone; + undef(@numbers); + undef($oneone); +} + +print "INPUT: \$N = $ARGV[0]\n"; +print "OUTPUT: $output\n"; + -- cgit From b6b74384b9f09082c406e24565dd5fac508443eb Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Fri, 2 Jul 2021 10:05:46 -0500 Subject: Create perl --- challenge-119/paul-fajman/perl | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-119/paul-fajman/perl diff --git a/challenge-119/paul-fajman/perl b/challenge-119/paul-fajman/perl new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/challenge-119/paul-fajman/perl @@ -0,0 +1 @@ + -- cgit From 1956511b5d4e5099a5122add81c907b443f0c585 Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Fri, 2 Jul 2021 10:06:06 -0500 Subject: Delete perl --- challenge-119/paul-fajman/perl | 1 - 1 file changed, 1 deletion(-) delete mode 100644 challenge-119/paul-fajman/perl diff --git a/challenge-119/paul-fajman/perl b/challenge-119/paul-fajman/perl deleted file mode 100644 index 8b13789179..0000000000 --- a/challenge-119/paul-fajman/perl +++ /dev/null @@ -1 +0,0 @@ - -- cgit From 316acf3cc0f6c5cb781224dadfd13525b40c0ed7 Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Fri, 2 Jul 2021 10:06:19 -0500 Subject: Create ch-1.pl --- challenge-119/paul-fajman/perl/ch-1.pl | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-119/paul-fajman/perl/ch-1.pl diff --git a/challenge-119/paul-fajman/perl/ch-1.pl b/challenge-119/paul-fajman/perl/ch-1.pl new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/challenge-119/paul-fajman/perl/ch-1.pl @@ -0,0 +1 @@ + -- cgit From c26da087402272113cd8393e96a0c8bcb48aeba8 Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Fri, 2 Jul 2021 10:06:47 -0500 Subject: Update ch-1.pl --- challenge-119/paul-fajman/perl/ch-1.pl | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/challenge-119/paul-fajman/perl/ch-1.pl b/challenge-119/paul-fajman/perl/ch-1.pl index 8b13789179..8175881325 100644 --- a/challenge-119/paul-fajman/perl/ch-1.pl +++ b/challenge-119/paul-fajman/perl/ch-1.pl @@ -1 +1,37 @@ +#/usr/bin/perl + +use strict; +use warnings; + +use POSIX; + +my $int = $ARGV[0]; +my $quo = $int; +my ($i, $rem); +my $total = 0; +my @nibbles=(); + +# Calculate binary number +while($quo ne 0) { + $rem = floor($quo % 2); + unshift @nibbles, $rem; + $quo = floor($quo/2); +} + +# Check that final number is 8 digits +while ($#nibbles+1 lt 8) { + unshift @nibbles, 0; +} + +# Swap the nibbles +my @final = splice(@nibbles, 4); +@final = (@final, @nibbles); + +# Calcuate the new decimal number +for ($i=7; $i>-1; $i--) { + $total+= $final[$i]*(2**(7-$i)); +} + +print "Input: \$N = $int\n"; +print "Output: $total\n"; -- cgit From 1a957ed2bf8665653288733ac1ce66b0a87adf2b Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Fri, 2 Jul 2021 10:07:02 -0500 Subject: Delete ch-1.pl --- challenge-119/paul-fajman/ch-1.pl | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 challenge-119/paul-fajman/ch-1.pl diff --git a/challenge-119/paul-fajman/ch-1.pl b/challenge-119/paul-fajman/ch-1.pl deleted file mode 100644 index 03918969c3..0000000000 --- a/challenge-119/paul-fajman/ch-1.pl +++ /dev/null @@ -1,36 +0,0 @@ -#/usr/bin/perl - -use strict; -use warnings; - -use POSIX; - -my $int = $ARGV[0]; -my $quo = $int; -my ($i, $rem); -my $total = 0; -my @nibbles=(); - -# Calculate binary number -while($quo ne 0) { - $rem = floor($quo % 2); - unshift @nibbles, $rem; - $quo = floor($quo/2); -} - -# Check that final number is 8 digits -while ($#nibbles+1 lt 8) { - unshift @nibbles, 0; -} - -# Swap the nibbles -my @final = splice(@nibbles, 4); -@final = (@final, @nibbles); - -# Calcuate the new decimal number -for ($i=7; $i>-1; $i--) { - $total+= $final[$i]*(2**(7-$i)); -} - -print "Input: \$N = $int\n"; -print "Output: $total\n"; -- cgit From 94e46372cf8cf4a68ed5099aeeec66ab21ceb4cb Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Fri, 2 Jul 2021 10:07:07 -0500 Subject: Delete ch-2.pl --- challenge-119/paul-fajman/ch-2.pl | 49 --------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 challenge-119/paul-fajman/ch-2.pl diff --git a/challenge-119/paul-fajman/ch-2.pl b/challenge-119/paul-fajman/ch-2.pl deleted file mode 100644 index 06299baa92..0000000000 --- a/challenge-119/paul-fajman/ch-2.pl +++ /dev/null @@ -1,49 +0,0 @@ -#/usr/bin/perl - -use strict; -use warnings; - -use POSIX; - -my $input = $ARGV[0]; -my @numbers; - -my ($quo, $rem, $i); -my $check=0; -my ($oneone, $output); - -for ($i=1;$i<$input+1;$i++) { - $quo = $i; - # Calculate base 4 number - # Later throw out any values with 0 - while ($quo ne 0) { - $rem = floor($quo % 4); - unshift @numbers, $rem; - $quo = floor($quo/4); - } - # Check for any digit with a 0 - foreach (@numbers) { - if ($_ eq 0) { - $check=1; - next; - } - $oneone.=$_; - } - - # Check if any digits are consecutive ones or if one was a 0; - if ($oneone =~ m/11/ || $check eq 1) { - undef($oneone); - undef(@numbers); - $check = 0; - $input++; - next; - } - - $output = $oneone; - undef(@numbers); - undef($oneone); -} - -print "INPUT: \$N = $ARGV[0]\n"; -print "OUTPUT: $output\n"; - -- cgit From 5ca123778f0bf377a2de08729ca85509f1358d02 Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Fri, 2 Jul 2021 10:07:19 -0500 Subject: Add files via upload --- challenge-119/paul-fajman/perl/ch-2.pl | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 challenge-119/paul-fajman/perl/ch-2.pl diff --git a/challenge-119/paul-fajman/perl/ch-2.pl b/challenge-119/paul-fajman/perl/ch-2.pl new file mode 100644 index 0000000000..06299baa92 --- /dev/null +++ b/challenge-119/paul-fajman/perl/ch-2.pl @@ -0,0 +1,49 @@ +#/usr/bin/perl + +use strict; +use warnings; + +use POSIX; + +my $input = $ARGV[0]; +my @numbers; + +my ($quo, $rem, $i); +my $check=0; +my ($oneone, $output); + +for ($i=1;$i<$input+1;$i++) { + $quo = $i; + # Calculate base 4 number + # Later throw out any values with 0 + while ($quo ne 0) { + $rem = floor($quo % 4); + unshift @numbers, $rem; + $quo = floor($quo/4); + } + # Check for any digit with a 0 + foreach (@numbers) { + if ($_ eq 0) { + $check=1; + next; + } + $oneone.=$_; + } + + # Check if any digits are consecutive ones or if one was a 0; + if ($oneone =~ m/11/ || $check eq 1) { + undef($oneone); + undef(@numbers); + $check = 0; + $input++; + next; + } + + $output = $oneone; + undef(@numbers); + undef($oneone); +} + +print "INPUT: \$N = $ARGV[0]\n"; +print "OUTPUT: $output\n"; + -- cgit From c29db6e7df729967c26e749e9cf831bdb5b1d853 Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Fri, 2 Jul 2021 10:09:40 -0500 Subject: Update ch-1.pl --- challenge-119/paul-fajman/perl/ch-1.pl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/challenge-119/paul-fajman/perl/ch-1.pl b/challenge-119/paul-fajman/perl/ch-1.pl index 8175881325..5a96f61777 100644 --- a/challenge-119/paul-fajman/perl/ch-1.pl +++ b/challenge-119/paul-fajman/perl/ch-1.pl @@ -1,5 +1,23 @@ #/usr/bin/perl +# Weekly Challenge 119 +# You are given a positive integer $N. +# Write a script to swap the two nibbles of the binary representation of the +# given number and print the decimal number of the new binary representation. +# +# Input: $N = 101 +# Output: 86 + +# Binary representation of decimal 101 is 1100101 or as 2 nibbles (0110)(0101). +# The swapped nibbles would be (0101)(0110) same as decimal 86. + +# Input: $N = 18 +# Output: 33 + +# Binary representation of decimal 18 is 10010 or as 2 nibbles (0001)(0010). +# The swapped nibbles would be (0010)(0001) same as decimal 33. +############################## + use strict; use warnings; -- cgit From d6c3b2aab247c84967ffba1e92232e3a43c34b28 Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Fri, 2 Jul 2021 10:10:03 -0500 Subject: Update ch-1.pl --- challenge-119/paul-fajman/perl/ch-1.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-119/paul-fajman/perl/ch-1.pl b/challenge-119/paul-fajman/perl/ch-1.pl index 5a96f61777..cd2b2f0165 100644 --- a/challenge-119/paul-fajman/perl/ch-1.pl +++ b/challenge-119/paul-fajman/perl/ch-1.pl @@ -1,6 +1,6 @@ #/usr/bin/perl -# Weekly Challenge 119 +# Weekly Challenge 119 Task #1 # You are given a positive integer $N. # Write a script to swap the two nibbles of the binary representation of the # given number and print the decimal number of the new binary representation. -- cgit From 66cea3b9b11f47e8ddad959ccabbf0b1018b5dde Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Fri, 2 Jul 2021 10:11:19 -0500 Subject: Update ch-2.pl --- challenge-119/paul-fajman/perl/ch-2.pl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/challenge-119/paul-fajman/perl/ch-2.pl b/challenge-119/paul-fajman/perl/ch-2.pl index 06299baa92..f764ea153a 100644 --- a/challenge-119/paul-fajman/perl/ch-2.pl +++ b/challenge-119/paul-fajman/perl/ch-2.pl @@ -1,5 +1,14 @@ #/usr/bin/perl +# Weekly Challenge 119 Task #2 +# Write a script to generate sequence starting at 1. Consider the +# increasing sequence of integers which contain only 1’s, 2’s and +# 3’s, and do not have any doublets of 1’s like below. Please +# accept a positive integer $N and print the $Nth term in the +# generated sequence. + +# 1, 2, 3, 12, 13, 21, 22, 23, 31, 32, 33, 121, 122, 123, 131 + use strict; use warnings; -- cgit