aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-06-25 21:13:56 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2021-06-25 21:13:56 +0100
commitb8f9d31801dcc2396202ddd158850baf210553d8 (patch)
tree1153e4321cf6e92eff9e3bdc9a0145841fb2a9a6
parent9eaf3a4b03ddecee21348d3bcefdda8b3eb65378 (diff)
downloadperlweeklychallenge-club-b8f9d31801dcc2396202ddd158850baf210553d8.tar.gz
perlweeklychallenge-club-b8f9d31801dcc2396202ddd158850baf210553d8.tar.bz2
perlweeklychallenge-club-b8f9d31801dcc2396202ddd158850baf210553d8.zip
Add solutions to challenge 011
-rw-r--r--challenge-011/paulo-custodio/ada/ch_1.adb22
-rw-r--r--challenge-011/paulo-custodio/awk/ch-1.awk20
-rw-r--r--challenge-011/paulo-custodio/basic/ch-1.bas15
-rw-r--r--challenge-011/paulo-custodio/bc/ch-1.bc2
-rw-r--r--challenge-011/paulo-custodio/c/ch-1.c21
-rw-r--r--challenge-011/paulo-custodio/cpp/ch-1.cpp24
-rw-r--r--challenge-011/paulo-custodio/forth/ch-1.fs21
-rw-r--r--challenge-011/paulo-custodio/lua/ch-1.lua19
-rw-r--r--challenge-011/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-011/paulo-custodio/python/ch-1.py17
-rw-r--r--challenge-011/paulo-custodio/t/test-1.yaml2
11 files changed, 162 insertions, 3 deletions
diff --git a/challenge-011/paulo-custodio/ada/ch_1.adb b/challenge-011/paulo-custodio/ada/ch_1.adb
new file mode 100644
index 0000000000..870141511b
--- /dev/null
+++ b/challenge-011/paulo-custodio/ada/ch_1.adb
@@ -0,0 +1,22 @@
+-- Challenge 011
+--
+-- Challenge #1
+-- Write a script that computes the equal point in the Fahrenheit and Celsius
+-- scales, knowing that the freezing point of water is 32oF and 0oC, and that
+-- the boiling point of water is 212oF and 100oC. This challenge was proposed
+-- by Laurent Rosenfeld.
+--
+-- F = (C * 9/5) + 32
+-- F = C = x
+-- => x = (x * 9/5) + 32
+-- <=> x * (1 - 9/5) = 32
+-- <=> x = 32 / (1 - 9/5)
+
+with Ada.Text_IO; use Ada.Text_IO;
+with Ada.Float_Text_IO; use Ada.Float_Text_IO;
+
+procedure ch_1 is
+ x : Float := 32.0 / (1.0 - 9.0/5.0);
+begin
+ Put(x, 1, 1, 0);
+end ch_1;
diff --git a/challenge-011/paulo-custodio/awk/ch-1.awk b/challenge-011/paulo-custodio/awk/ch-1.awk
new file mode 100644
index 0000000000..dace20ed06
--- /dev/null
+++ b/challenge-011/paulo-custodio/awk/ch-1.awk
@@ -0,0 +1,20 @@
+#!/usr/bin/gawk
+
+# Challenge 011
+#
+# Challenge #1
+# Write a script that computes the equal point in the Fahrenheit and Celsius
+# scales, knowing that the freezing point of water is 32oF and 0oC, and that
+# the boiling point of water is 212oF and 100oC. This challenge was proposed
+# by Laurent Rosenfeld.
+#
+# F = (C * 9/5) + 32
+# F = C = x
+# => x = (x * 9/5) + 32
+# <=> x * (1 - 9/5) = 32
+# <=> x = 32 / (1 - 9/5)
+
+BEGIN {
+ printf "%.1f\n", 32 / (1 - 9/5);
+ exit 0;
+}
diff --git a/challenge-011/paulo-custodio/basic/ch-1.bas b/challenge-011/paulo-custodio/basic/ch-1.bas
new file mode 100644
index 0000000000..3db9aae2c0
--- /dev/null
+++ b/challenge-011/paulo-custodio/basic/ch-1.bas
@@ -0,0 +1,15 @@
+' Challenge 011
+'
+' Challenge #1
+' Write a script that computes the equal point in the Fahrenheit and Celsius
+' scales, knowing that the freezing point of water is 32oF and 0oC, and that
+' the boiling point of water is 212oF and 100oC. This challenge was proposed
+' by Laurent Rosenfeld.
+
+' F = (C * 9/5) + 32
+' F = C = x
+' => x = (x * 9/5) + 32
+' <=> x * (1 - 9/5) = 32
+' <=> x = 32 / (1 - 9/5)
+
+print using "###.#"; 32 / (1 - 9/5)
diff --git a/challenge-011/paulo-custodio/bc/ch-1.bc b/challenge-011/paulo-custodio/bc/ch-1.bc
index c8e8ea3a1c..993a702761 100644
--- a/challenge-011/paulo-custodio/bc/ch-1.bc
+++ b/challenge-011/paulo-custodio/bc/ch-1.bc
@@ -34,6 +34,6 @@ define newton(x0) {
}
t = newton(0)
-scale = 0
+scale = 1
t/1
quit
diff --git a/challenge-011/paulo-custodio/c/ch-1.c b/challenge-011/paulo-custodio/c/ch-1.c
new file mode 100644
index 0000000000..5bd246acc9
--- /dev/null
+++ b/challenge-011/paulo-custodio/c/ch-1.c
@@ -0,0 +1,21 @@
+/*
+Challenge 011
+
+Challenge #1
+Write a script that computes the equal point in the Fahrenheit and Celsius
+scales, knowing that the freezing point of water is 32oF and 0oC, and that
+the boiling point of water is 212oF and 100oC. This challenge was proposed
+by Laurent Rosenfeld.
+
+F = (C * 9/5) + 32
+F = C = x
+=> x = (x * 9/5) + 32
+<=> x * (1 - 9/5) = 32
+<=> x = 32 / (1 - 9/5)
+*/
+
+#include <stdio.h>
+
+int main() {
+ printf("%.1f\n", 32.0 / (1.0 - 9.0/5.0));
+}
diff --git a/challenge-011/paulo-custodio/cpp/ch-1.cpp b/challenge-011/paulo-custodio/cpp/ch-1.cpp
new file mode 100644
index 0000000000..e3096ba9da
--- /dev/null
+++ b/challenge-011/paulo-custodio/cpp/ch-1.cpp
@@ -0,0 +1,24 @@
+/*
+Challenge 011
+
+Challenge #1
+Write a script that computes the equal point in the Fahrenheit and Celsius
+scales, knowing that the freezing point of water is 32oF and 0oC, and that
+the boiling point of water is 212oF and 100oC. This challenge was proposed
+by Laurent Rosenfeld.
+
+F = (C * 9/5) + 32
+F = C = x
+=> x = (x * 9/5) + 32
+<=> x * (1 - 9/5) = 32
+<=> x = 32 / (1 - 9/5)
+*/
+
+#include <iostream>
+#include <iomanip>
+using namespace std;
+
+int main() {
+ cout << fixed << setprecision(1)
+ << 32.0 / (1.0 - 9.0/5.0) << endl;
+}
diff --git a/challenge-011/paulo-custodio/forth/ch-1.fs b/challenge-011/paulo-custodio/forth/ch-1.fs
new file mode 100644
index 0000000000..fa042abc6d
--- /dev/null
+++ b/challenge-011/paulo-custodio/forth/ch-1.fs
@@ -0,0 +1,21 @@
+#! /usr/bin/env gforth
+
+\ Challenge 011
+\
+\ Challenge #1
+\ Write a script that computes the equal point in the Fahrenheit and Celsius
+\ scales, knowing that the freezing point of water is 32oF and 0oC, and that
+\ the boiling point of water is 212oF and 100oC. This challenge was proposed
+\ by Laurent Rosenfeld.
+\
+\ F = (C * 9/5) + 32
+\ F = C = x
+\ => x = (x * 9/5) + 32
+\ <=> x * (1 - 9/5) = 32
+\ <=> x = 32 / (1 - 9/5)
+
+: ##.# ( d -- )
+ SWAP OVER DABS <# # [CHAR] . HOLD #S ROT SIGN #> TYPE ;
+
+32.0e0 1.0e0 9.0e0 5.0e0 F/ F- F/
+10.0e0 F* F>D ##.# CR BYE
diff --git a/challenge-011/paulo-custodio/lua/ch-1.lua b/challenge-011/paulo-custodio/lua/ch-1.lua
new file mode 100644
index 0000000000..64a8437662
--- /dev/null
+++ b/challenge-011/paulo-custodio/lua/ch-1.lua
@@ -0,0 +1,19 @@
+#!/usr/bin/env lua
+
+--[[
+Challenge 011
+
+Challenge #1
+Write a script that computes the equal point in the Fahrenheit and Celsius
+scales, knowing that the freezing point of water is 32oF and 0oC, and that
+the boiling point of water is 212oF and 100oC. This challenge was proposed
+by Laurent Rosenfeld.
+
+F = (C * 9/5) + 32
+F = C = x
+=> x = (x * 9/5) + 32
+<=> x * (1 - 9/5) = 32
+<=> x = 32 / (1 - 9/5)
+--]]
+
+io.write(string.format("%.1f", 32 / (1 - 9/5)), "\n")
diff --git a/challenge-011/paulo-custodio/perl/ch-1.pl b/challenge-011/paulo-custodio/perl/ch-1.pl
index 0aa31c4947..5580fa104a 100644
--- a/challenge-011/paulo-custodio/perl/ch-1.pl
+++ b/challenge-011/paulo-custodio/perl/ch-1.pl
@@ -21,4 +21,4 @@ $exp->addVariable('x');
$exp->setExpression("(x * 9/5) + 32 - x");
my $result = $exp->newtonRaphson('x', 0) or die $exp->getError;
-say $result;
+say sprintf("%.1f", $result);
diff --git a/challenge-011/paulo-custodio/python/ch-1.py b/challenge-011/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..d8f93b7668
--- /dev/null
+++ b/challenge-011/paulo-custodio/python/ch-1.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+
+# Challenge 011
+#
+# Challenge #1
+# Write a script that computes the equal point in the Fahrenheit and Celsius
+# scales, knowing that the freezing point of water is 32oF and 0oC, and that
+# the boiling point of water is 212oF and 100oC. This challenge was proposed
+# by Laurent Rosenfeld.
+#
+# F = (C * 9/5) + 32
+# F = C = x
+# => x = (x * 9/5) + 32
+# <=> x * (1 - 9/5) = 32
+# <=> x = 32 / (1 - 9/5)
+
+print(32 / (1 - 9/5))
diff --git a/challenge-011/paulo-custodio/t/test-1.yaml b/challenge-011/paulo-custodio/t/test-1.yaml
index 5ea8bd975e..1382753816 100644
--- a/challenge-011/paulo-custodio/t/test-1.yaml
+++ b/challenge-011/paulo-custodio/t/test-1.yaml
@@ -2,4 +2,4 @@
cleanup:
args:
input:
- output: -40
+ output: -40.0