Skip to content

Instantly share code, notes, and snippets.

@adamcrussell
adamcrussell / Makefile.PL
Created May 16, 2019 20:18
Integrating C++ and Perl with SWIG
use ExtUtils::MakeMaker;
WriteMakefile(
"NAME" => "Perfect", # Name of package
"OBJECT" => "perfect.o perfect_wrap.o" # Object files
);
@adamcrussell
adamcrussell / ch-1t.pl
Created May 19, 2019 03:47
Computing Perfect Numbers with Threads
use strict;
use warnings;
##
# Write a script that computes the first five perfect numbers.
# A perfect number is an integer that is the sum of its positive
# proper divisors (all divisors except itself).
##
use Thread;
use constant THREAD_COUNT => 4;
@adamcrussell
adamcrussell / ch-1.pl
Created May 26, 2019 13:04
Perl Weekly Challenge 009
use strict;
use warnings;
##
# Write a script that finds the first square number that has at least 5 distinct digits.
##
use boolean;
use constant X_0 => 100;
sub is_distinct_five{
my($n) = @_;
@adamcrussell
adamcrussell / ch-1.pl
Last active June 2, 2019 13:10
Perl Weekly Challenge 010
use strict;
use warnings;
##
# Write a script to encode/decode Roman numerals.
##
use boolean;
use Fstream;
use Parse::YYLex;
use RomanParser;
@adamcrussell
adamcrussell / ch-1.pl
Last active June 9, 2019 03:48
Perl Weekly Challenge 011
use strict;
use warnings;
##
# Write a script that computes the equal point in the Fahrenheit and Celsius
# scales, knowing that the freezing point of water is 32 °F and 0 °C, and
# that the boiling point of water is 212 °F and 100 °C.
# °F = (°C * 9/5) + 32
##
for my $c (-100 .. 100){
my $f = ($c * (9/5)) + 32;
@adamcrussell
adamcrussell / ch-1.pl
Created June 16, 2019 04:51
Perl Weekly Challenge 012
use strict;
use warnings;
##
# The numbers formed by adding one to the products of the smallest primes
# are called the Euclid Numbers. Write a script that finds the smallest
# Euclid Number that is not prime
##
use boolean;
use LWP::UserAgent;
use constant PRIME_URL => "http://primes.utm.edu/lists/small/10000.txt";
@adamcrussell
adamcrussell / ch-1.pl
Created June 23, 2019 05:12
Perl Weekly Challenge 013
use strict;
use warnings;
##
# Write a script to print the date of last Friday of every month of a given year.
##
use constant YEAR => 2019;
use constant FRIDAY => 5;
use constant JANUARY => 1;
use constant FEBRUARY => 2;
use constant MARCH => 3;
@adamcrussell
adamcrussell / ch-1.pl
Last active June 30, 2019 04:52
Perl Weekly Challenge 014
use strict;
use warnings;
##
# Write a script to generate Van Eck’s sequence starts with 0.
##
my $i = 1;
my @sequence = (0, 0);
print join(" ", @sequence) . " ";
{
my $last_index = (sort { $b <=> $a} grep { $sequence[$_] == $sequence[$i] } 0..(@sequence - 2))[0];
@adamcrussell
adamcrussell / ch-1.pl
Created July 7, 2019 20:04
Perl Weekly Challenge 015
use strict;
use warnings;
##
# Write a script to generate first 10 strong and weak prime numbers.
##
use boolean;
use LWP::UserAgent;
use constant PRIME_URL => "http://primes.utm.edu/lists/small/100000.txt";
sub get_primes{
@adamcrussell
adamcrussell / ch-1.pl
Last active July 14, 2019 14:01
Perl Weekly Challenge 016
use strict;
use warnings;
##
# At a party a pie is to be shared by 100 guests.
# The first guest gets 1% of the pie, the second
# guest gets 2% of the remaining pie, the third
# gets 3% of the remaining pie, the fourth gets 4% and so on.
# Write a script that figures out which guest gets the largest piece of pie.
##
use constant PIE_SIZE => 100;