Add simple scripts used in interviews

This commit is contained in:
Tracey Clark 2024-06-08 15:49:48 -05:00
commit d1a39bf85d
2 changed files with 65 additions and 0 deletions

20
interview_scripts/fizzbuzz.pl Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env perl
use strict;
use warnings;
#Fizz buzz example
# For 1 .. 10 if odd print fizz, otherwise print buzz
for my $num (1..10) {
# print "$num: "; # Debug
if ($num % 2) {
print "fizz\n";
}
else {
print "buzz\n";
}
}

45
interview_scripts/test1.pl Executable file
View file

@ -0,0 +1,45 @@
#!/usr/bin/env perl
#use Modern::Perl;
use strict;
use warnings;
use List::Util qw( reduce );
my @array_in = ();
while (<STDIN>) {
chomp($_);
last if ($_ eq '');
push(@array_in, $_);
}
foreach (@array_in) {
printf "%s\n", $_;
}
print "Array in is @array_in\n";
get_smallest_missing(@array_in);
sub get_smallest_missing {
my (@numbers_array) = @_;
my $integer = 0;
# If 1 is not present in the array it is the lowest integer not in the array
if ( ! grep( /1/, @numbers_array ) ) {
print "1 is not in the array, it is the lowest integer not in array\n";
$integer = 1;
return $integer;
}
else {
$integer =
reduce { $numbers_array[$a] <= $numbers_array[$b] ? $a : $b }
grep { $numbers_array[$_] >= 2 }
0..$#numbers_array;
print "Returning integer $integer\n";
return $integer;
}
}