aboutsummaryrefslogtreecommitdiff
path: root/challenge-246
diff options
context:
space:
mode:
authorBarrOff <58253563+BarrOff@users.noreply.github.com>2023-12-10 23:27:56 +0100
committerBarrOff <58253563+BarrOff@users.noreply.github.com>2023-12-10 23:27:56 +0100
commit296b0b18e9fe1e6c29256466a5542762ddb1f61b (patch)
treeecefb025e90d938489271b818c54aca02afde346 /challenge-246
parent37772285a1ce55828a066cfc6ffdc6bbf048f54b (diff)
downloadperlweeklychallenge-club-296b0b18e9fe1e6c29256466a5542762ddb1f61b.tar.gz
perlweeklychallenge-club-296b0b18e9fe1e6c29256466a5542762ddb1f61b.tar.bz2
perlweeklychallenge-club-296b0b18e9fe1e6c29256466a5542762ddb1f61b.zip
feat: add solutions for challenge 246 from BarrOff
Diffstat (limited to 'challenge-246')
-rw-r--r--challenge-246/barroff/julia/ch-1.jl5
-rwxr-xr-xchallenge-246/barroff/nim/ch_1.nims24
-rw-r--r--challenge-246/barroff/perl/ch-1.pl28
-rw-r--r--challenge-246/barroff/raku/ch-1.p610
4 files changed, 67 insertions, 0 deletions
diff --git a/challenge-246/barroff/julia/ch-1.jl b/challenge-246/barroff/julia/ch-1.jl
new file mode 100644
index 0000000000..6635ef6e03
--- /dev/null
+++ b/challenge-246/barroff/julia/ch-1.jl
@@ -0,0 +1,5 @@
+#!/usr/bin/env julia
+
+using Random: shuffle
+
+[println(x) for x in shuffle(1:49)[1:6]]
diff --git a/challenge-246/barroff/nim/ch_1.nims b/challenge-246/barroff/nim/ch_1.nims
new file mode 100755
index 0000000000..6d1f18161b
--- /dev/null
+++ b/challenge-246/barroff/nim/ch_1.nims
@@ -0,0 +1,24 @@
+#!/usr/bin/env -S nim e --hints:off
+import std/[cmdline, parseutils, random, sequtils]
+
+proc six_out_of_fortynine[T: SomeInteger](count: T = 6) =
+ var
+ lotteryNumbers = toSeq(1..49)
+ # set up rng
+ randomize()
+ # shuffle the numbers
+ shuffle(lotteryNumbers)
+ for i in lotteryNumbers[0..count - 1]:
+ echo i
+
+proc main() =
+ if paramCount() != 0:
+ var
+ parsedInt: int
+ for argument in commandLineParams():
+ if parseInt(argument, parsedInt, 0) != 0:
+ six_out_of_fortynine(parsedInt)
+ return
+ six_out_of_fortynine()
+
+main()
diff --git a/challenge-246/barroff/perl/ch-1.pl b/challenge-246/barroff/perl/ch-1.pl
new file mode 100644
index 0000000000..a73614c78a
--- /dev/null
+++ b/challenge-246/barroff/perl/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+
+use v5.38;
+
+sub six_out_of_fortynine ( $count = 6 ) {
+ my %numbers;
+ $numbers{$_} = rand() for 1 .. 49;
+ my @keys = sort { $numbers{$a} <=> $numbers{$b} } keys(%numbers);
+ say for @keys[ 0 .. $count - 1 ];
+ return undef;
+}
+
+sub MAIN() {
+ if (@ARGV) {
+
+ #| Run command line argument
+ die "Number <$ARGV[0]> is not in range 1-49!"
+ if $ARGV[0] < 1
+ or $ARGV[0] > 49;
+ six_out_of_fortynine( $ARGV[0] );
+ }
+ else {
+ #| Run default case
+ six_out_of_fortynine();
+ }
+}
+
+MAIN();
diff --git a/challenge-246/barroff/raku/ch-1.p6 b/challenge-246/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..b6c04bdef0
--- /dev/null
+++ b/challenge-246/barroff/raku/ch-1.p6
@@ -0,0 +1,10 @@
+#!/usr/bin/env raku
+
+sub six-out-of-fortynine(Int $count where $count ∈ Set(1..49) = 6) {
+ .say for pick($count, 1 .. 49);
+}
+
+#| Take user provided count like 7
+multi sub MAIN(Int $count where $count ∈ Set(1..49) = 6) {
+ six-out-of-fortynine($count);
+}