From e292b631e646b149bd7ecf5739f4325d15db7111 Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Tue, 12 Dec 2023 20:42:10 -0500 Subject: solution for 246.1 in Perl --- challenge-246/adam-russell/perl/ch-1.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 challenge-246/adam-russell/perl/ch-1.pl (limited to 'challenge-246') 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; +} -- cgit