diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2024-09-09 11:34:37 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2024-09-09 11:34:37 +0000 |
| commit | a29bbc7dd407a5cf8d78b111a494ffa5b460298d (patch) | |
| tree | 9c2b19ac74fd8c1f2a1232a90286937ab15fede9 | |
| parent | e83f7e4d7285a22af4a40efa15e28272d79749e2 (diff) | |
| download | perlweeklychallenge-club-a29bbc7dd407a5cf8d78b111a494ffa5b460298d.tar.gz perlweeklychallenge-club-a29bbc7dd407a5cf8d78b111a494ffa5b460298d.tar.bz2 perlweeklychallenge-club-a29bbc7dd407a5cf8d78b111a494ffa5b460298d.zip | |
w286 - Task 1 & 2
| -rwxr-xr-x | challenge-286/perlboy1967/perl/ch1.pl | 36 | ||||
| -rwxr-xr-x | challenge-286/perlboy1967/perl/ch2.pl | 42 |
2 files changed, 78 insertions, 0 deletions
diff --git a/challenge-286/perlboy1967/perl/ch1.pl b/challenge-286/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..c593627d8d --- /dev/null +++ b/challenge-286/perlboy1967/perl/ch1.pl @@ -0,0 +1,36 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 286 +- L<https://theweeklychallenge.org/blog/perl-weekly-challenge-286> + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Self Spammer +Submitted by: David Ferrone + +Write a program which outputs one word of its own script / source code at random. +A word is anything between whitespace, including symbols. + +=cut + +use v5.32; +use feature qw(signatures); +no warnings qw(experimental::signatures); +use common::sense; + +use Test2::V0 qw(-no_srand); + +use File::Slurp; + +sub selfSpammer { + my @w = grep /\S/, split /\s/, read_file(__FILE__); + $w[rand @w]; +} + +srand(0); + +is(selfSpammer,'Dijke'); + +done_testing; diff --git a/challenge-286/perlboy1967/perl/ch2.pl b/challenge-286/perlboy1967/perl/ch2.pl new file mode 100755 index 0000000000..43a9e828c9 --- /dev/null +++ b/challenge-286/perlboy1967/perl/ch2.pl @@ -0,0 +1,42 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 286 +- L<https://theweeklychallenge.org/blog/perl-weekly-challenge-286> + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Order Game +Submitted by: Mohammad Sajid Anwar + +You are given an array of integers, @ints, whose length is a power of 2. + +Write a script to play the order game (min and max) and return the last element. + +=cut + +use v5.32; +use feature qw(signatures); +no warnings qw(experimental::signatures); +use common::sense; + +use Test2::V0 qw(-no_srand); + +use DDP; +use List::AllUtils qw(min max natatime); + +sub orderGame (@ints) { + while (scalar @ints > 2) { + my @i; + push(@i,min(splice(@ints,0,2)),max(splice(@ints,0,2))) while (@ints); + @ints = @i; + } + min(@ints); +} + +is(1,orderGame(2,1,4,5,6,3,0,2)); +is(0,orderGame(0,5,3,2)); +is(2,orderGame(9,2,1,4,5,6,0,7,3,1,3,5,7,9,0,8)); + +done_testing; |
