diff options
| author | Walt Mankowski <waltman@pobox.com> | 2020-02-18 21:10:06 -0500 |
|---|---|---|
| committer | Walt Mankowski <waltman@pobox.com> | 2020-02-18 21:10:06 -0500 |
| commit | 7cbf085c8abb6f1ef95215f63462ae0e96b14ce0 (patch) | |
| tree | a5450c1c9dc3a3c8a83199c637af8ab647b97acb /challenge-048 | |
| parent | 3aad5eea0347f5e7f74a24cd382f369bd5b3db56 (diff) | |
| download | perlweeklychallenge-club-7cbf085c8abb6f1ef95215f63462ae0e96b14ce0.tar.gz perlweeklychallenge-club-7cbf085c8abb6f1ef95215f63462ae0e96b14ce0.tar.bz2 perlweeklychallenge-club-7cbf085c8abb6f1ef95215f63462ae0e96b14ce0.zip | |
perl code for challenge 48-1
Diffstat (limited to 'challenge-048')
| -rw-r--r-- | challenge-048/walt-mankowski/perl/ch-1.pl | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-048/walt-mankowski/perl/ch-1.pl b/challenge-048/walt-mankowski/perl/ch-1.pl new file mode 100644 index 0000000000..2d4ba9651e --- /dev/null +++ b/challenge-048/walt-mankowski/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use feature qw(:5.30); +use experimental qw(signatures); + +# TASK #1 +# Survivor +# There are 50 people standing in a circle in position 1 to 50. The +# person standing at position 1 has a sword. He kills the next person +# i.e. standing at position 2 and pass on the sword to the immediate +# next i.e. person standing at position 3. Now the person at position 3 +# does the same and it goes on until only one survives. + +# Write a script to find out the survivor. + +my @person = 1..50; +my $i = 0; +while (@person > 1) { + my $j = ($i + 1) % @person; + splice(@person, $j, 1); + $i = ($i + 1) % @person; +} + +say "The survivor is @person"; |
