aboutsummaryrefslogtreecommitdiff
path: root/challenge-246
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-12-10 23:28:33 +0000
committerGitHub <noreply@github.com>2023-12-10 23:28:33 +0000
commit7de753881d9cdb1377e26b12e26b1b2b8953c3b0 (patch)
treef605d225d3893e6cf7443a2bfa2c4fe4ca0ed329 /challenge-246
parent37772285a1ce55828a066cfc6ffdc6bbf048f54b (diff)
parent3a4e4c0e03278a51c6c150ef1df4b16e2381efd1 (diff)
downloadperlweeklychallenge-club-7de753881d9cdb1377e26b12e26b1b2b8953c3b0.tar.gz
perlweeklychallenge-club-7de753881d9cdb1377e26b12e26b1b2b8953c3b0.tar.bz2
perlweeklychallenge-club-7de753881d9cdb1377e26b12e26b1b2b8953c3b0.zip
Merge pull request #9217 from mattneleigh/pwc246
new file: challenge-246/mattneleigh/perl/ch-1.pl
Diffstat (limited to 'challenge-246')
-rwxr-xr-xchallenge-246/mattneleigh/perl/ch-1.pl67
1 files changed, 67 insertions, 0 deletions
diff --git a/challenge-246/mattneleigh/perl/ch-1.pl b/challenge-246/mattneleigh/perl/ch-1.pl
new file mode 100755
index 0000000000..324fdd932e
--- /dev/null
+++ b/challenge-246/mattneleigh/perl/ch-1.pl
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use English;
+
+################################################################################
+# Begin main execution
+################################################################################
+
+print("\n");
+for(1 .. 5){
+ printf(
+ "Ausgabe: \@lottozahlen = %s\n",
+ join(
+ ", ",
+ map(
+ sprintf("%2d", $_),
+ sechs_von_neunundvierzig()
+ )
+ )
+ );
+}
+print("\n");
+
+exit(0);
+################################################################################
+# End main execution; subroutines follow
+################################################################################
+
+
+
+################################################################################
+# Generate six unique random integers in the range of 1 to 49, inclusive, for
+# use in the German lottery.
+# Takes no arguments.
+# Returns:
+# * A list of six unique random integers in the range of 1 to 49, inclusive,
+# sorted in ascending order (e.g. ( 1, 12, 15, 36, 42, 49 ) )
+################################################################################
+sub sechs_von_neunundvierzig{
+
+ # A pool of numbers from which to select;
+ # this will also serve as a table of numbers
+ # not yet selected
+ my @numbers = (1 .. 49);
+
+ return(
+ # 3: Sort the list of selected numbers in
+ # ascending order
+ sort(
+ { $a <=> $b }
+ # 2: Make a list of six numbers randomly
+ # selected from the pool
+ map(
+ # 1: Randomly select- and remove- a number
+ # from the pool
+ splice(@numbers, int(rand(scalar(@numbers))), 1),
+ 1 .. 6
+ )
+ )
+ );
+
+}
+
+
+