diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-03-28 20:12:14 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-03-28 20:12:14 +0100 |
| commit | df9f48775d3de31d899a0630fd5773e311093e4e (patch) | |
| tree | 7eeb492954d7641c5ed49dac5eaa3424f74311cb /challenge-105 | |
| parent | 95ec2d8186c8cf1c78051aac4bd4a3e8cf23a13d (diff) | |
| download | perlweeklychallenge-club-df9f48775d3de31d899a0630fd5773e311093e4e.tar.gz perlweeklychallenge-club-df9f48775d3de31d899a0630fd5773e311093e4e.tar.bz2 perlweeklychallenge-club-df9f48775d3de31d899a0630fd5773e311093e4e.zip | |
- Added guest contributions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-105')
18 files changed, 155 insertions, 0 deletions
diff --git a/challenge-105/laurent-rosenfeld/awk/ch-1.awk b/challenge-105/laurent-rosenfeld/awk/ch-1.awk new file mode 100644 index 0000000000..dd72280134 --- /dev/null +++ b/challenge-105/laurent-rosenfeld/awk/ch-1.awk @@ -0,0 +1,6 @@ +# run e.g. as: $ awk -v input=120 -f root.awk +BEGIN { + for (i = 1; i <= 10; i++) { + printf "%2i ยจ%10.3f\n", i, input ** (1/i); + } +} diff --git a/challenge-105/laurent-rosenfeld/bc/ch-1.bc b/challenge-105/laurent-rosenfeld/bc/ch-1.bc new file mode 100644 index 0000000000..c09ad986e5 --- /dev/null +++ b/challenge-105/laurent-rosenfeld/bc/ch-1.bc @@ -0,0 +1 @@ +echo 'a = 248832; for(i=1;i<=5;i++) { print i; print " "; print e(l(a)/i); print "\n"}' | bc -l diff --git a/challenge-105/laurent-rosenfeld/c/ch-1.c b/challenge-105/laurent-rosenfeld/c/ch-1.c new file mode 100644 index 0000000000..443d8a023a --- /dev/null +++ b/challenge-105/laurent-rosenfeld/c/ch-1.c @@ -0,0 +1,14 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +#define DEFAULT_IN 248832 + +int main(int argc, char *argv[]) { + printf("%s\n", argv[1]); + int in = argc == 2 ? atoi( argv[1]) : DEFAULT_IN; + for (int i = 1; i <= 10; i++) { + printf("%2i %10.3f \n", i, pow (in, 1.0/i)); + }; + return 0; +} diff --git a/challenge-105/laurent-rosenfeld/d/ch-1.d b/challenge-105/laurent-rosenfeld/d/ch-1.d new file mode 100644 index 0000000000..b493ac3c42 --- /dev/null +++ b/challenge-105/laurent-rosenfeld/d/ch-1.d @@ -0,0 +1,10 @@ +import std.stdio; +import std.math; + +void main() { + auto input = 248832; + for (int i = 1; i <= 8; i++) { + double root = pow(input, 1.0/i); + writeln(i, " ", root); + } +} diff --git a/challenge-105/laurent-rosenfeld/dart/ch-1.dart b/challenge-105/laurent-rosenfeld/dart/ch-1.dart new file mode 100644 index 0000000000..da0644d634 --- /dev/null +++ b/challenge-105/laurent-rosenfeld/dart/ch-1.dart @@ -0,0 +1,9 @@ +import 'dart:math'; + +void main() { + var input = 248832; + for (int i = 1; i <= 8; i++) { + var root = pow(input, (1/i)); + print("$i $root"); + } +} diff --git a/challenge-105/laurent-rosenfeld/gembase/ch-1.dml b/challenge-105/laurent-rosenfeld/gembase/ch-1.dml new file mode 100644 index 0000000000..583940c66b --- /dev/null +++ b/challenge-105/laurent-rosenfeld/gembase/ch-1.dml @@ -0,0 +1,13 @@ +PROCEDURE_FORM ROOT (#in) + if (#in = "") + #input = 248832 + else + #input = #in + end_if + #i = 1 + while(#i <= 10) + #root = #input ^ (1.0/#i) + error /text_only (mask("!-@@", #i) & mask("!-@@@@@@@@@@0.@@@", #root)) + #i = #i + 1 + end_while +END_FORM diff --git a/challenge-105/laurent-rosenfeld/go/ch-1.go b/challenge-105/laurent-rosenfeld/go/ch-1.go new file mode 100644 index 0000000000..5dbf2af11f --- /dev/null +++ b/challenge-105/laurent-rosenfeld/go/ch-1.go @@ -0,0 +1,12 @@ +package main +import ( + "fmt" + "math" +) +func main() { + const input = 248832 + + for i := 1; i <= 10; i++ { + fmt.Printf("%2d\t%10.3f\n", i, math.Pow(input, 1.0/float64(i))) + } +} diff --git a/challenge-105/laurent-rosenfeld/java/Main.java b/challenge-105/laurent-rosenfeld/java/Main.java new file mode 100644 index 0000000000..88a4741537 --- /dev/null +++ b/challenge-105/laurent-rosenfeld/java/Main.java @@ -0,0 +1,9 @@ +class Main { + public static void main(String args[]) { + double input = Double.parseDouble(args[0]); + for (int i = 1; i <= 10; i++) { + double root = Math.pow(input, 1.0 / i ); + System.out.format("%2d %10.3f\n", i, root); + } + } +} diff --git a/challenge-105/laurent-rosenfeld/julia/ch-1.julia b/challenge-105/laurent-rosenfeld/julia/ch-1.julia new file mode 100644 index 0000000000..64bbfd3dbe --- /dev/null +++ b/challenge-105/laurent-rosenfeld/julia/ch-1.julia @@ -0,0 +1,4 @@ +input = 248832 +for i = 1:10 + @printf("%2d %10.3f\n", i, input ^ (1/i) ) +end diff --git a/challenge-105/laurent-rosenfeld/kotlink/ch-1.kt b/challenge-105/laurent-rosenfeld/kotlink/ch-1.kt new file mode 100644 index 0000000000..b07111c49d --- /dev/null +++ b/challenge-105/laurent-rosenfeld/kotlink/ch-1.kt @@ -0,0 +1,8 @@ +fun main() { + val input = 248832; + for (i in 1..10) { + val root = "%12.3f".format(Math.pow(input * 1.0, 1.0/i)) + val formatted_i = "%2d".format(i) + println("$formatted_i $root") + } +} diff --git a/challenge-105/laurent-rosenfeld/lua/ch-1.lua b/challenge-105/laurent-rosenfeld/lua/ch-1.lua new file mode 100644 index 0000000000..8f460af37a --- /dev/null +++ b/challenge-105/laurent-rosenfeld/lua/ch-1.lua @@ -0,0 +1,4 @@ +input = 248832 +for i = 1, 10 do + print (string.format("%2d %10.3f", i, input ^ (1/i))) +end diff --git a/challenge-105/laurent-rosenfeld/nim/ch-1.nim b/challenge-105/laurent-rosenfeld/nim/ch-1.nim new file mode 100644 index 0000000000..0e18196166 --- /dev/null +++ b/challenge-105/laurent-rosenfeld/nim/ch-1.nim @@ -0,0 +1,6 @@ +import math + +var input = 248832.0 +for i in 1..8: + var root = pow(input, 1.0 / float(i)) + echo i, " ", root diff --git a/challenge-105/laurent-rosenfeld/python/ch-2.py b/challenge-105/laurent-rosenfeld/python/ch-2.py new file mode 100644 index 0000000000..66882ddcab --- /dev/null +++ b/challenge-105/laurent-rosenfeld/python/ch-2.py @@ -0,0 +1,14 @@ +import sys +input = sys.argv[1] if len(sys.argv) > 1 else "Katie" +start = input[0] +suffix = input[1:] +vowels = { "A", "E", "I", "O", "U"} + +bosuffix = f'bo-{suffix}' if (start == 'B' or start in vowels) else f'bo-b{suffix}' +fosuffix = f'fo-{suffix}' if (start == 'F' or start in vowels) else f'fo-f{suffix}' +mosuffix = f'mo-{suffix}' if (start == 'M' or start in vowels) else f'mo-m{suffix}' + +print(f'{input}, {input}, {bosuffix}') +print(f'Bonana-fanna {fosuffix}') +print(f'Fee fi {mosuffix}') +print(f'{input}!') diff --git a/challenge-105/laurent-rosenfeld/ruby/ch-1.rb b/challenge-105/laurent-rosenfeld/ruby/ch-1.rb new file mode 100644 index 0000000000..8bfd9535e3 --- /dev/null +++ b/challenge-105/laurent-rosenfeld/ruby/ch-1.rb @@ -0,0 +1,6 @@ +$input = 248832 +for i in 1 .. 8 do + root = $input ** (1.0/i) + puts "#{i} #{root}" +end +print "\n" diff --git a/challenge-105/laurent-rosenfeld/rust/ch-1.rust b/challenge-105/laurent-rosenfeld/rust/ch-1.rust new file mode 100644 index 0000000000..6843df50ed --- /dev/null +++ b/challenge-105/laurent-rosenfeld/rust/ch-1.rust @@ -0,0 +1,7 @@ +fn main() { + let input = 248832f64; + for i in 1..11 { + let root = input.powf(1.0/i as f64); + println!("{:2} {:10.3}", i, root); + } +} diff --git a/challenge-105/laurent-rosenfeld/scala/ch-1.scala b/challenge-105/laurent-rosenfeld/scala/ch-1.scala new file mode 100644 index 0000000000..5fb04d82a3 --- /dev/null +++ b/challenge-105/laurent-rosenfeld/scala/ch-1.scala @@ -0,0 +1,7 @@ +object root extends App { + val in: Int = if (args.size == 1) args(0).toInt else 248832 + for (i <- 1 to 10) { + val root = scala.math.pow(in, (1 / i.toDouble)) + println(f"$i%2d $root%10.3f") + } +} diff --git a/challenge-105/laurent-rosenfeld/scala/ch-2.scala b/challenge-105/laurent-rosenfeld/scala/ch-2.scala new file mode 100644 index 0000000000..ba4304c6be --- /dev/null +++ b/challenge-105/laurent-rosenfeld/scala/ch-2.scala @@ -0,0 +1,18 @@ +object nameGame extends App { + val in: String = if (args.size == 1) args(0) else "Katie" + val start = in.substring(0, 1) + val suffix = in.substring(1) + val vowels = Map("A" -> 1, "E" -> 1, "I" -> 1, "O" -> 1, "U" -> 1) + + val bosuffix = if (start == 'B' || vowels.contains(start)) + s"bo-$suffix" else s"bo-b$suffix" + val fosuffix = if (start == 'F' || vowels.contains(start)) + s"fo-$suffix" else s"fo-f$suffix" + val mosuffix = if (start == 'M' || vowels.contains(start)) + s"mo-$suffix" else s"mo-m$suffix" + + println(s"$in, $in, $bosuffix") + println(s"Bonana-fanna $fosuffix") + println(s"Fee fi $mosuffix") + println(s"$in!") +} diff --git a/challenge-105/laurent-rosenfeld/visual-basic/ch-1.vb b/challenge-105/laurent-rosenfeld/visual-basic/ch-1.vb new file mode 100644 index 0000000000..8055a2899e --- /dev/null +++ b/challenge-105/laurent-rosenfeld/visual-basic/ch-1.vb @@ -0,0 +1,7 @@ +Module VBModule + Sub Main() + for i as Integer = 1 to 5 + Console.WriteLine(248832 ^ (1/i)) + next + End Sub +End Module |
