Last active
June 9, 2019 03:48
-
-
Save adamcrussell/811a6bd724bd8adc92a7352e046661a1 to your computer and use it in GitHub Desktop.
Perl Weekly Challenge 011
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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