aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-06-04 05:01:53 +0100
committerGitHub <noreply@github.com>2019-06-04 05:01:53 +0100
commit79132e559aad165401b8520a9a62ad2cc4fb84de (patch)
tree346990c5c5fe94d05b321825907bdaae61c847cf
parent6cd5697e97037fc448bc84f1479d5494679cd936 (diff)
parent5898864ef1fb2aa96a17d6105766105039e3817d (diff)
downloadperlweeklychallenge-club-79132e559aad165401b8520a9a62ad2cc4fb84de.tar.gz
perlweeklychallenge-club-79132e559aad165401b8520a9a62ad2cc4fb84de.tar.bz2
perlweeklychallenge-club-79132e559aad165401b8520a9a62ad2cc4fb84de.zip
Merge pull request #220 from khalidelboray/patch-6
Perl6 Challenge #1 Solution
-rw-r--r--challenge-011/khalid/perl6/ch-1.p649
1 files changed, 49 insertions, 0 deletions
diff --git a/challenge-011/khalid/perl6/ch-1.p6 b/challenge-011/khalid/perl6/ch-1.p6
new file mode 100644
index 0000000000..e7581d4b8b
--- /dev/null
+++ b/challenge-011/khalid/perl6/ch-1.p6
@@ -0,0 +1,49 @@
+Usage:
+ ch.p6 <kelvin>
+ ch.p6 [--kelvin=<K>]
+ ch.p6 [--celsius=<C>]
+ ch.p6 [--rankine=<R>]
+ ch.p6 [--fahrenheit=<F>]
+
+ <kelvin> Kelvin Value
+ --kelvin=<K> Kelvin Value
+ --celsius=<C> Celsius Value
+ --rankine=<R> Rankine value
+ --fahrenheit=<F> Fahrenheit value
+
+subset K of Real:D where * >= 0;
+subset C of Str:D where * ~~ /'-'? \d */;
+subset R of Int:D where * > 0;
+subset F of C;
+multi sub MAIN (
+ K $kelvin #= Kelvin Value
+) {
+ convert($kelvin);
+}
+multi sub MAIN (
+ K :$kelvin #= Kelvin Value
+) {
+ convert ($kelvin);
+}
+multi sub MAIN (
+ C :$celsius #= Celsius Value
+) {
+ convert($celsius + 273.15);
+}
+multi sub MAIN (
+ R :$rankine #= Rankine value
+) {
+ convert($rankine / 1.8);
+}
+multi sub MAIN (
+ F :$fahrenheit #= Fahrenheit value
+) {
+ convert(($fahrenheit + 459.67) / 1.8);
+}
+sub convert ( K $kelvin is copy ) {
+ say " { $kelvin }K";
+ say " { $kelvin- 273.15 }C";
+ say " { $kelvin * 1.8 - 459.67 }F";
+ say " { $kelvin* 1.8 }R";
+}
+