diff options
| author | Adam Russell <ac.russell@live.com> | 2023-12-12 20:42:10 -0500 |
|---|---|---|
| committer | Adam Russell <ac.russell@live.com> | 2023-12-12 20:42:10 -0500 |
| commit | e292b631e646b149bd7ecf5739f4325d15db7111 (patch) | |
| tree | 40bd8ba68550414ed3cc7f3f53cd12a78e0c5ec8 | |
| parent | 75dfef10b6f5580cf581d824ff046c2afa87b159 (diff) | |
| download | perlweeklychallenge-club-e292b631e646b149bd7ecf5739f4325d15db7111.tar.gz perlweeklychallenge-club-e292b631e646b149bd7ecf5739f4325d15db7111.tar.bz2 perlweeklychallenge-club-e292b631e646b149bd7ecf5739f4325d15db7111.zip | |
solution for 246.1 in Perl
| -rw-r--r-- | challenge-246/adam-russell/perl/ch-1.pl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-246/adam-russell/perl/ch-1.pl b/challenge-246/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..b462c6e959 --- /dev/null +++ b/challenge-246/adam-russell/perl/ch-1.pl @@ -0,0 +1,22 @@ +use v5.38; +## +# 6 out of 49 is a German lottery. +# Write a script that outputs six unique random integers from the range 1 to 49. +## +package SixOfFourtyNine{ + use Math::Random::Secure q/irand/; + sub pick_six{ + my @six; + { + my $r = irand(49) + 1; + push @six, $r if 0 == grep {$_ == $r} @six; + redo unless @six == 6; + } + return sort {$a <=> $b} @six; + } + +} + +package main{ + say join q/, /, SixOfFourtyNine::pick_six; +} |
