From b8f9d31801dcc2396202ddd158850baf210553d8 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Fri, 25 Jun 2021 21:13:56 +0100 Subject: Add solutions to challenge 011 --- challenge-011/paulo-custodio/ada/ch_1.adb | 22 ++++++++++++++++++++++ challenge-011/paulo-custodio/awk/ch-1.awk | 20 ++++++++++++++++++++ challenge-011/paulo-custodio/basic/ch-1.bas | 15 +++++++++++++++ challenge-011/paulo-custodio/bc/ch-1.bc | 2 +- challenge-011/paulo-custodio/c/ch-1.c | 21 +++++++++++++++++++++ challenge-011/paulo-custodio/cpp/ch-1.cpp | 24 ++++++++++++++++++++++++ challenge-011/paulo-custodio/forth/ch-1.fs | 21 +++++++++++++++++++++ challenge-011/paulo-custodio/lua/ch-1.lua | 19 +++++++++++++++++++ challenge-011/paulo-custodio/perl/ch-1.pl | 2 +- challenge-011/paulo-custodio/python/ch-1.py | 17 +++++++++++++++++ challenge-011/paulo-custodio/t/test-1.yaml | 2 +- 11 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 challenge-011/paulo-custodio/ada/ch_1.adb create mode 100644 challenge-011/paulo-custodio/awk/ch-1.awk create mode 100644 challenge-011/paulo-custodio/basic/ch-1.bas create mode 100644 challenge-011/paulo-custodio/c/ch-1.c create mode 100644 challenge-011/paulo-custodio/cpp/ch-1.cpp create mode 100644 challenge-011/paulo-custodio/forth/ch-1.fs create mode 100644 challenge-011/paulo-custodio/lua/ch-1.lua create mode 100644 challenge-011/paulo-custodio/python/ch-1.py 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 + +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 +#include +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 -- cgit