Skip to content

Instantly share code, notes, and snippets.

@adamcrussell
Last active June 9, 2019 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcrussell/811a6bd724bd8adc92a7352e046661a1 to your computer and use it in GitHub Desktop.
Save adamcrussell/811a6bd724bd8adc92a7352e046661a1 to your computer and use it in GitHub Desktop.
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;
if($f == $c){
print "°F = °C at $f\n";
}
}
use strict;
use warnings;
##
# Write a script to create an Identity Matrix for the given size.
# For example, if the size is 4, then create Identity Matrix 4x4.
##
use constant SIZE => 10;
my @a;
for my $i (0 .. SIZE - 1){
my @b = (0) x SIZE;
$b[$i] = 1;
push @a, \@b;
}
print SIZE . " x " . SIZE . " identity matrix:\n";
for my $i (0 .. SIZE - 1){
print "\t" . join(" ", @{$a[$i]}) . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment