aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-052/user-person/perl/ch-1-CORRECTED.pl86
-rwxr-xr-xchallenge-052/user-person/perl/ch-1.pl29
-rw-r--r--challenge-052/user-person/python/ch-1-CORRECTED.py81
-rwxr-xr-xchallenge-052/user-person/python/ch-1.py17
4 files changed, 34 insertions, 179 deletions
diff --git a/challenge-052/user-person/perl/ch-1-CORRECTED.pl b/challenge-052/user-person/perl/ch-1-CORRECTED.pl
deleted file mode 100644
index 0f5ebee9d0..0000000000
--- a/challenge-052/user-person/perl/ch-1-CORRECTED.pl
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/usr/bin/env perl
-
-###########################################################################
-# script name: ch-1-CORRECTED.pl #
-# #
-# https://github.com/user-person #
-# #
-# https://perlweeklychallenge.org/blog/perl-weekly-challenge-052/ #
-# #
-# Stepping Numbers #
-# #
-# Write a script to accept two numbers between 100 and 999. It should #
-# then print all Stepping Numbers between them. #
-# #
-# A number is called a stepping number if the adjacent digits have a #
-# difference of 1. For example, 456 is a stepping number but 129 is not. #
-# #
-###########################################################################
-
-use strict;
-use warnings;
-use FindBin;
-
-my @step = ();
-my $UPPER_LIMIT = 1000;
-my $LOWER_LIMIT = 99;
-
-for (my $i = 1; $i < 10; ++$i) {
- if ($i < 8) { # UP UP
- push @step, ($i * 100) + ( $i + 1 ) * 10 + ($i + 2);
- }
- if ($i > 1) { # DOWN DOWN
- push @step, ($i * 100) + ( $i - 1 ) * 10 + ($i - 2);
- }
- if ($i < 9) { # UP DOWN
- push @step, ($i * 100) + ( $i + 1 ) * 10 + $i;
- }
- push @step, ($i * 100) + ( $i - 1 ) * 10 + $i; # DOWN UP
-}
-
-@step = sort { $a <=> $b } @step;
-
-if (
- scalar @ARGV != 2
-
- or $ARGV[0] !~ m|\A\d{3}\Z|
- or $ARGV[0] < $LOWER_LIMIT
- or $ARGV[0] > $UPPER_LIMIT
-
- or $ARGV[1] !~ m|\A\d{3}\Z|
- or $ARGV[1] < $LOWER_LIMIT
- or $ARGV[1] > $UPPER_LIMIT
-
- ) {
- print STDERR "$FindBin::Script requires 2 arguments between 100 and 999.\n";
- exit(1);
-}
-
-my ($min, $max) = (0, 0);
-
-if ($ARGV[0] < $ARGV[1]) {
- $min = $ARGV[0];
- $max = $ARGV[1];
-} elsif ($ARGV[1] < $ARGV[0]) {
- $min = $ARGV[1];
- $max = $ARGV[0];
-} else {
- $max = $min = $ARGV[0];
-}
-
-my $commaFlag = 0;
-
-exit if $step[0] > $max or $step[-1] < $min;
-
-LOOP:
-foreach (@step) {
- if ($_ >= $min and $_ <= $max) {
- print ", " if $commaFlag;
- print "$_";
- $commaFlag = 1;
- } elsif ($commaFlag) {
- last LOOP;
- }
-}
-
-print "\n" if $commaFlag;
diff --git a/challenge-052/user-person/perl/ch-1.pl b/challenge-052/user-person/perl/ch-1.pl
index acf198b2c4..0329f79eea 100755
--- a/challenge-052/user-person/perl/ch-1.pl
+++ b/challenge-052/user-person/perl/ch-1.pl
@@ -25,22 +25,33 @@ my @step = ();
my $UPPER_LIMIT = 1000;
my $LOWER_LIMIT = 99;
-for (my $i = 1; $i < 8; ++$i) {
- push @step, ($i * 100) + ( $i + 1 ) * 10 + ($i + 2);
+for (my $i = 1; $i < 10; ++$i) {
+ if ($i < 8) { # UP UP
+ push @step, ($i * 100) + ( $i + 1 ) * 10 + ($i + 2);
+ }
+ if ($i > 1) { # DOWN DOWN
+ push @step, ($i * 100) + ( $i - 1 ) * 10 + ($i - 2);
+ }
+ if ($i < 9) { # UP DOWN
+ push @step, ($i * 100) + ( $i + 1 ) * 10 + $i;
+ }
+ push @step, ($i * 100) + ( $i - 1 ) * 10 + $i; # DOWN UP
}
+@step = sort { $a <=> $b } @step;
+
if (
scalar @ARGV != 2
- or $ARGV[0] !~ m|\A\d{3}\Z|
- or $ARGV[0] < $LOWER_LIMIT
- or $ARGV[0] > $UPPER_LIMIT
+ or $ARGV[0] !~ m|\A\d{3}\Z|
+ or $ARGV[0] < $LOWER_LIMIT
+ or $ARGV[0] > $UPPER_LIMIT
- or $ARGV[1] !~ m|\A\d{3}\Z|
- or $ARGV[1] < $LOWER_LIMIT
- or $ARGV[1] > $UPPER_LIMIT
+ or $ARGV[1] !~ m|\A\d{3}\Z|
+ or $ARGV[1] < $LOWER_LIMIT
+ or $ARGV[1] > $UPPER_LIMIT
- ) {
+ ) {
print STDERR "$FindBin::Script requires 2 arguments between 100 and 999.\n";
exit(1);
}
diff --git a/challenge-052/user-person/python/ch-1-CORRECTED.py b/challenge-052/user-person/python/ch-1-CORRECTED.py
deleted file mode 100644
index 0fa2fa5bdd..0000000000
--- a/challenge-052/user-person/python/ch-1-CORRECTED.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/usr/bin/env python3
-
-###########################################################################
-# script name: ch-1-CORRECTED.py #
-# #
-# https://github.com/user-person #
-# #
-# https://perlweeklychallenge.org/blog/perl-weekly-challenge-052/ #
-# #
-# Stepping Numbers #
-# #
-# Write a script to accept two numbers between 100 and 999. It should #
-# then print all Stepping Numbers between them. #
-# #
-# A number is called a stepping number if the adjacent digits have a #
-# difference of 1. For example, 456 is a stepping number but 129 is not. #
-# #
-###########################################################################
-
-import os
-import re
-import sys
-
-step = []
-UPPER_LIMIT = 1000
-LOWER_LIMIT = 99
-
-for i in range(1,10):
- if i < 8: # UP UP
- step.append( (i * 100) + ((i+1) * 10) + (i+2) )
-
- if i > 1: # DOWN DOWN
- step.append( (i * 100) + ((i-1) * 10) + (i-2) )
-
- if i < 9: # UP DOWN
- step.append( (i * 100) + ((i+1) * 10) + i )
-
- step.append( (i * 100) + ((i-1) * 10) + i ) # DOWN UP
-
-step.sort()
-
-errorString = os.path.basename(sys.argv[0]) + ' requires 2 arguments between 100 and 999.'
-
-if len(sys.argv) != 3:
- print(errorString)
- exit(1)
-
-args = [int(arg) for arg in sys.argv[1:]]
-
-for arg in args:
- if arg < LOWER_LIMIT or arg > UPPER_LIMIT:
- print(errorString)
- exit(1)
-
-max = min = 0
-
-if args[0] < args[1]:
- min = args[0]
- max = args[1]
-elif args[1] < args[0]:
- min = args[1]
- max = args[0]
-else:
- max = min = args[0]
-
-commaFlag = False
-
-if step[0] > max or step[-1] < min:
- exit(0)
-
-for num in step:
- if num >= min and num <= max:
- if commaFlag:
- print(', ', end='')
- print(num, end='')
- commaFlag = True
- elif commaFlag:
- break
-
-if commaFlag:
- print()
diff --git a/challenge-052/user-person/python/ch-1.py b/challenge-052/user-person/python/ch-1.py
index b7a0685098..98b642394d 100755
--- a/challenge-052/user-person/python/ch-1.py
+++ b/challenge-052/user-person/python/ch-1.py
@@ -25,15 +25,26 @@ step = []
UPPER_LIMIT = 1000
LOWER_LIMIT = 99
-for i in range(1,8):
- step.append( (i * 100) + ((i+1) * 10) + (i+2) )
+for i in range(1,10):
+ if i < 8: # UP UP
+ step.append( (i * 100) + ((i+1) * 10) + (i+2) )
+
+ if i > 1: # DOWN DOWN
+ step.append( (i * 100) + ((i-1) * 10) + (i-2) )
+
+ if i < 9: # UP DOWN
+ step.append( (i * 100) + ((i+1) * 10) + i )
+
+ step.append( (i * 100) + ((i-1) * 10) + i ) # DOWN UP
+
+step.sort()
errorString = os.path.basename(sys.argv[0]) + ' requires 2 arguments between 100 and 999.'
if len(sys.argv) != 3:
print(errorString)
exit(1)
-
+
args = [int(arg) for arg in sys.argv[1:]]
for arg in args: