Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
2
Task/Exponentiation-order/00-META.yaml
Normal file
2
Task/Exponentiation-order/00-META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Exponentiation_order
|
||||
32
Task/Exponentiation-order/00-TASK.txt
Normal file
32
Task/Exponentiation-order/00-TASK.txt
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
This task will demonstrate the order of [[wp:Exponentiation|exponentiation]] <big>('''x<sup>y</sup>''') </big> when there are multiple exponents.
|
||||
|
||||
(Many programming languages, especially those with extended─precision integer arithmetic, usually support one of <big> <code>**</code>, <code>^</code>, <code>↑</code> </big> or some such for exponentiation.)
|
||||
|
||||
|
||||
;Task requirements
|
||||
Show the result of a language's evaluation of multiple exponentiation (either as an integer or floating point).
|
||||
|
||||
If your language's exponentiation operator is not one of the usual ones, please comment on how to recognize it.
|
||||
|
||||
|
||||
Using whatever operator or syntax your language supports (if any), show the results in three lines (with identification):
|
||||
<big>
|
||||
::::* 5**3**2
|
||||
::::* (5**3)**2
|
||||
::::* 5**(3**2)
|
||||
</big>
|
||||
|
||||
<br>
|
||||
If there are other methods (or formats) of multiple exponentiations, show them as well.
|
||||
|
||||
|
||||
;See also:
|
||||
* MathWorld entry: [http://mathworld.wolfram.com/Exponentiation.html exponentiation]
|
||||
|
||||
|
||||
;Related tasks:
|
||||
* [[Exponentiation_operator|exponentiation operator]]
|
||||
* [[Arbitrary-precision_integers_(included)|arbitrary-precision integers (included)]]
|
||||
* [[Exponentiation with infix operators in (or operating on) the base]]
|
||||
<br><br>
|
||||
|
||||
3
Task/Exponentiation-order/11l/exponentiation-order.11l
Normal file
3
Task/Exponentiation-order/11l/exponentiation-order.11l
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
print(5 ^ 3 ^ 2)
|
||||
print((5 ^ 3) ^ 2)
|
||||
print(5 ^ (3 ^ 2))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
print( ( "5**3**2: ", 5**3**2, newline ) );
|
||||
print( ( "(5**3)**2: ", (5**3)**2, newline ) );
|
||||
print( ( "5**(3**2): ", 5**(3**2), newline ) )
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
begin
|
||||
write( "5**3**2: ", round( 5 ** 3 ** 2 ) );
|
||||
write( "(5**3)**2: ", round( ( 5 ** 3 ) ** 2 ) );
|
||||
write( "5**(3**2): ", round( 5 ** round( 3 ** 2 ) ) )
|
||||
end.
|
||||
7
Task/Exponentiation-order/AWK/exponentiation-order.awk
Normal file
7
Task/Exponentiation-order/AWK/exponentiation-order.awk
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# syntax: GAWK -f EXPONENTIATION_ORDER.AWK
|
||||
BEGIN {
|
||||
printf("5^3^2 = %d\n",5^3^2)
|
||||
printf("(5^3)^2 = %d\n",(5^3)^2)
|
||||
printf("5^(3^2) = %d\n",5^(3^2))
|
||||
exit(0)
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
|
||||
|
||||
PROC Main()
|
||||
REAL r2,r3,r5,tmp1,tmp2
|
||||
|
||||
Put(125) PutE() ;clear screen
|
||||
|
||||
IntToReal(2,r2)
|
||||
IntToReal(3,r3)
|
||||
IntToReal(5,r5)
|
||||
|
||||
PrintE("There is no power operator in Action!")
|
||||
PrintE("Power function for REAL type is used.")
|
||||
PrintE("But the precision is insufficient.")
|
||||
Power(r5,r3,tmp1)
|
||||
Power(tmp1,r2,tmp2)
|
||||
Print("(5^3)^2=")
|
||||
PrintRE(tmp2)
|
||||
|
||||
Power(r3,r2,tmp1)
|
||||
Power(r5,tmp1,tmp2)
|
||||
Print("5^(3^2)=")
|
||||
PrintRE(tmp2)
|
||||
RETURN
|
||||
9
Task/Exponentiation-order/Ada/exponentiation-order.ada
Normal file
9
Task/Exponentiation-order/Ada/exponentiation-order.ada
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Exponentation_Order is
|
||||
use Ada.Text_IO;
|
||||
begin
|
||||
-- Put_Line ("5**3**2 : " & Natural'(5**3**2)'Image);
|
||||
Put_Line ("(5**3)**2 : " & Natural'((5**3)**2)'Image);
|
||||
Put_Line ("5**(3**2) : " & Natural'(5**(3**2))'Image);
|
||||
end Exponentation_Order;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
set r1 to 5 ^ 3 ^ 2 -- Changes to 5 ^ (3 ^ 2) when compiled.
|
||||
set r2 to (5 ^ 3) ^ 2
|
||||
set r3 to 5 ^ (3 ^ 2)
|
||||
|
||||
return "5 ^ 3 ^ 2 = " & r1 & "
|
||||
(5 ^ 3) ^ 2 = " & r2 & "
|
||||
5 ^ (3 ^ 2) = " & r3
|
||||
|
|
@ -0,0 +1 @@
|
|||
?"5^3^2 = "5 ^ 3 ^ 2 CHR$ (13)"(5^3)^2 = "(5 ^ 3) ^ 2 CHR$ (13)"5^(3^2) = "5 ^ (3 ^ 2);
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
print 5^3^2
|
||||
print (5^3)^2
|
||||
print 5^(3^2)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
print "5^3^2 = "; 5^3^2
|
||||
print "(5^3)^2 = "; (5^3)^2
|
||||
print "5^(3^2) = "; 5^(3^2)
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
PRINT "5^3^2 = "; 5^3^2
|
||||
PRINT "(5^3)^2 = "; (5^3)^2
|
||||
PRINT "5^(3^2) = "; 5^(3^2)
|
||||
|
|
@ -0,0 +1 @@
|
|||
put$str$("5^3^2: " 5^3^2 "\n(5^3)^2: " (5^3)^2 "\n5^(3^2): " 5^(3^2) \n)
|
||||
9
Task/Exponentiation-order/C++/exponentiation-order-1.cpp
Normal file
9
Task/Exponentiation-order/C++/exponentiation-order-1.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
int main() {
|
||||
std::cout << "(5 ^ 3) ^ 2 = " << (uint) pow(pow(5,3), 2) << std::endl;
|
||||
std::cout << "5 ^ (3 ^ 2) = "<< (uint) pow(5, (pow(3, 2)));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
13
Task/Exponentiation-order/C++/exponentiation-order-2.cpp
Normal file
13
Task/Exponentiation-order/C++/exponentiation-order-2.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
enum my_int {};
|
||||
inline my_int operator^(my_int a, my_int b) { return static_cast<my_int>(pow(a,b)); }
|
||||
|
||||
int main() {
|
||||
my_int x = 5, y = 3, z = 2;
|
||||
std::cout << "(5 ^ 3) ^ 2 = " << ((x^y)^z) << std::endl;
|
||||
std::cout << "5 ^ (3 ^ 2) = "<< (x^(y^z));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
20
Task/Exponentiation-order/C-sharp/exponentiation-order.cs
Normal file
20
Task/Exponentiation-order/C-sharp/exponentiation-order.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
|
||||
namespace exponents
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
/*
|
||||
* Like C, C# does not have an exponent operator.
|
||||
* Exponentiation is done via Math.Pow, which
|
||||
* only takes two arguments
|
||||
*/
|
||||
Console.WriteLine(Math.Pow(Math.Pow(5, 3), 2));
|
||||
Console.WriteLine(Math.Pow(5, Math.Pow(3, 2)));
|
||||
Console.Read();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
10
Task/Exponentiation-order/C/exponentiation-order.c
Normal file
10
Task/Exponentiation-order/C/exponentiation-order.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include<stdio.h>
|
||||
#include<math.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("(5 ^ 3) ^ 2 = %.0f",pow(pow(5,3),2));
|
||||
printf("\n5 ^ (3 ^ 2) = %.0f",pow(5,pow(3,2)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
7
Task/Exponentiation-order/CLU/exponentiation-order.clu
Normal file
7
Task/Exponentiation-order/CLU/exponentiation-order.clu
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
start_up = proc ()
|
||||
po: stream := stream$primary_output()
|
||||
|
||||
stream$putl(po, "5**3**2 = " || int$unparse(5**3**2))
|
||||
stream$putl(po, "(5**3)**2 = " || int$unparse((5**3)**2))
|
||||
stream$putl(po, "5**(3**2) = " || int$unparse(5**(3**2)))
|
||||
end start_up
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
10 print "5^3^2 = "5^3^2
|
||||
20 print "(5^3)^2 = "(5^3)^2
|
||||
30 print "5^(3^2) = "5^(3^2)
|
||||
13
Task/Exponentiation-order/Clojure/exponentiation-order.clj
Normal file
13
Task/Exponentiation-order/Clojure/exponentiation-order.clj
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
(use 'clojure.math.numeric-tower)
|
||||
;; (5**3)**2
|
||||
(expt (expt 5 3) 2) ; => 15625
|
||||
|
||||
;; 5**(3**2)
|
||||
(expt 5 (expt 3 2)) ; => 1953125
|
||||
|
||||
;; (5**3)**2 alternative: use reduce
|
||||
(reduce expt [5 3 2]) ; => 15625
|
||||
|
||||
;; 5**(3**2) alternative: evaluating right-to-left with reduce requires a small modification
|
||||
(defn rreduce [f coll] (reduce #(f %2 %) (reverse coll)))
|
||||
(rreduce expt [5 3 2]) ; => 1953125
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(expt (expt 5 3) 2)
|
||||
(expt 5 (expt 3 2))
|
||||
8
Task/Exponentiation-order/D/exponentiation-order.d
Normal file
8
Task/Exponentiation-order/D/exponentiation-order.d
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
void main() {
|
||||
import std.stdio, std.math, std.algorithm;
|
||||
|
||||
writefln("5 ^^ 3 ^^ 2 = %7d", 5 ^^ 3 ^^ 2);
|
||||
writefln("(5 ^^ 3) ^^ 2 = %7d", (5 ^^ 3) ^^ 2);
|
||||
writefln("5 ^^ (3 ^^ 2) = %7d", 5 ^^ (3 ^^ 2));
|
||||
writefln("[5, 3, 2].reduce!pow = %7d", [5, 3, 2].reduce!pow);
|
||||
}
|
||||
6
Task/Exponentiation-order/Dart/exponentiation-order.dart
Normal file
6
Task/Exponentiation-order/Dart/exponentiation-order.dart
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import 'dart:math' show pow;
|
||||
|
||||
void main() {
|
||||
print('(5 ^ 3) ^ 2 = ${pow(pow(5, 3), 2)}');
|
||||
print('5 ^ (3 ^ 2) = ${pow(5, (pow(3, 2)))}');
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
procedure ExponentDemo(Memo: TMemo);
|
||||
begin
|
||||
Memo.Lines.Add('5^3^2 = '+FloatToStrF(Power(5,Power(3,2)),ffNumber,18,0));
|
||||
Memo.Lines.Add('(5^3)^2 = '+FloatToStrF(Power(Power(5,3),2),ffNumber,18,0));
|
||||
Memo.Lines.Add('5^(3^2) = '+FloatToStrF(Power(5,Power(3,2)),ffNumber,18,0));
|
||||
end;
|
||||
16
Task/Exponentiation-order/EchoLisp/exponentiation-order.l
Normal file
16
Task/Exponentiation-order/EchoLisp/exponentiation-order.l
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
;; the standard and secure way is to use the (expt a b) function
|
||||
(expt 5 (expt 3 2)) ;; 5 ** ( 3 ** 2)
|
||||
→ 1953125
|
||||
(expt (expt 5 3) 2) ;; (5 ** 3) ** 2
|
||||
→ 15625
|
||||
|
||||
;; infix EchoLisp may use the ** operator, which right associates
|
||||
(lib 'match)
|
||||
(load 'infix.glisp)
|
||||
|
||||
(5 ** 3 ** 2)
|
||||
→ 1953125
|
||||
((5 ** 3) ** 2)
|
||||
→ 15625
|
||||
(5 ** (3 ** 2))
|
||||
→ 1953125
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
USING: formatting math.functions ;
|
||||
|
||||
5 3 2 ^ ^
|
||||
"5 3 2 ^ ^ %d\n" printf
|
||||
|
||||
5 3 ^ 2 ^
|
||||
"5 3 ^ 2 ^ %d\n" printf
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
USING: formatting infix ;
|
||||
|
||||
[infix 5**3**2 infix]
|
||||
"5**3**2 = %d\n" printf
|
||||
|
||||
[infix (5**3)**2 infix]
|
||||
"(5**3)**2 = %d\n" printf
|
||||
|
||||
[infix 5**(3**2) infix]
|
||||
"5**(3**2) = %d\n" printf
|
||||
3
Task/Exponentiation-order/Fortran/exponentiation-order.f
Normal file
3
Task/Exponentiation-order/Fortran/exponentiation-order.f
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
write(*, "(a, i0)") "5**3**2 = ", 5**3**2
|
||||
write(*, "(a, i0)") "(5**3)**2 = ", (5**3)**2
|
||||
write(*, "(a, i0)") "5**(3**2) = ", 5**(3**2)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
' FB 1.05.0
|
||||
|
||||
' The exponentation operator in FB is ^ rather than **.
|
||||
' In the absence of parenthesis this operator is
|
||||
' left-associative. So the first example
|
||||
' will have the same value as the second example.
|
||||
|
||||
Print "5^3^2 =>"; 5^3^2
|
||||
Print "(5^3)^2 =>"; (5^3)^2
|
||||
Print "5^(3^2) =>"; 5^(3^2)
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
println["5^3^2 = " + 5^3^2]
|
||||
println["(5^3)^2 = " + (5^3)^2]
|
||||
println["5^(3^2) = " + 5^(3^2)]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
print "(5^3)^2 = "; (5^3)^2
|
||||
print "5^(3^2) = "; 5^(3^2)
|
||||
print
|
||||
print "fn pow( fn pow(5,3), 2 ) = "; fn pow( fn pow(5,3), 2 )
|
||||
print "fn pow( 5, fn pow(3,2 ) ) = "; fn pow( 5, fn pow(3,2 ) )
|
||||
|
||||
HandleEvents
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
10 PRINT "5^3^2 =" 5^3^2
|
||||
20 PRINT "(5^3)^2 =" (5^3)^2
|
||||
30 PRINT "5^(3^2) =" 5^(3^2)
|
||||
14
Task/Exponentiation-order/Go/exponentiation-order.go
Normal file
14
Task/Exponentiation-order/Go/exponentiation-order.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import "math"
|
||||
|
||||
func main() {
|
||||
var a, b, c float64
|
||||
a = math.Pow(5, math.Pow(3, 2))
|
||||
b = math.Pow(math.Pow(5, 3), 2)
|
||||
c = math.Pow(5, math.Pow(3, 2))
|
||||
fmt.Printf("5^3^2 = %.0f\n", a)
|
||||
fmt.Printf("(5^3)^2 = %.0f\n", b)
|
||||
fmt.Printf("5^(3^2) = %.0f\n", c)
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
println(" 5 ** 3 ** 2 == " + 5**3**2)
|
||||
println("(5 ** 3)** 2 == " + (5**3)**2)
|
||||
println(" 5 **(3 ** 2)== " + 5**(3**2))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
100 PRINT "5^3^2 =";5^3^2
|
||||
110 PRINT "(5^3)^2 =";(5^3)^2
|
||||
120 PRINT "5^(3^2) =";5^(3^2)
|
||||
6
Task/Exponentiation-order/J/exponentiation-order.j
Normal file
6
Task/Exponentiation-order/J/exponentiation-order.j
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
5^3^2
|
||||
1.95312e6
|
||||
(5^3)^2
|
||||
15625
|
||||
5^(3^2)
|
||||
1.95312e6
|
||||
2
Task/Exponentiation-order/Jq/exponentiation-order-1.jq
Normal file
2
Task/Exponentiation-order/Jq/exponentiation-order-1.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
jq -n 'pow(pow(5;3);2)'
|
||||
15625
|
||||
3
Task/Exponentiation-order/Jq/exponentiation-order-2.jq
Normal file
3
Task/Exponentiation-order/Jq/exponentiation-order-2.jq
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def pow: reduce .[1:] as $i (.[0]; pow(.;$i))
|
||||
|
||||
[5,3,2] | pow
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
@show 5 ^ 3 ^ 2 # default: power operator is read right-to-left
|
||||
@show (5 ^ 3) ^ 2
|
||||
@show 5 ^ (3 ^ 2)
|
||||
@show reduce(^, [5, 3, 2])
|
||||
@show foldl(^, [5, 3, 2]) # guarantees left associativity
|
||||
@show foldr(^, [5, 3, 2]) # guarantees right associativity
|
||||
23
Task/Exponentiation-order/Kotlin/exponentiation-order.kotlin
Normal file
23
Task/Exponentiation-order/Kotlin/exponentiation-order.kotlin
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// version 1.0.5-2
|
||||
|
||||
infix fun Int.ipow(exp: Int): Int = when {
|
||||
exp < 0 -> throw IllegalArgumentException("negative exponents not allowed")
|
||||
exp == 0 -> 1
|
||||
else -> {
|
||||
var ans = 1
|
||||
var base = this
|
||||
var e = exp
|
||||
while(e != 0) {
|
||||
if (e and 1 == 1) ans *= base
|
||||
e = e shr 1
|
||||
base *= base
|
||||
}
|
||||
ans
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println("5**3**2 = ${5 ipow 3 ipow 2}")
|
||||
println("(5**3)**2 = ${(5 ipow 3) ipow 2}")
|
||||
println("5**(3**2) = ${5 ipow (3 ipow 2)}")
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
'{pow {pow 5 3} 2}
|
||||
-> {pow {pow 5 3} 2}
|
||||
'{pow 5 {pow 3 2}}
|
||||
-> {pow 5 {pow 3 2}}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
writeln " 5^3^2: ", 5^3^2
|
||||
writeln "(5^3)^2: ", (5^3)^2
|
||||
writeln "5^(3^2): ", 5^(3^2)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
5 ^ 3 ^ 2. ;; 1953125
|
||||
(5 ^ 3) ^ 2. ;; 15625
|
||||
5 ^ (3 ^ 2). ;; 1953125
|
||||
3
Task/Exponentiation-order/Lua/exponentiation-order.lua
Normal file
3
Task/Exponentiation-order/Lua/exponentiation-order.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
print("5^3^2 = " .. 5^3^2)
|
||||
print("(5^3)^2 = " .. (5^3)^2)
|
||||
print("5^(3^2) = " .. 5^(3^2))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
10 PRINT "5^3^2 =" 5^3^2
|
||||
20 PRINT "(5^3)^2 =" (5^3)^2
|
||||
30 PRINT "5^(3^2) =" 5^(3^2)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
5^3^2;
|
||||
(5^3)^2;
|
||||
5^(3^2);
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
a = "5^3^2";
|
||||
Print[a <> " = " <> ToString[ToExpression[a]]]
|
||||
b = "(5^3)^2";
|
||||
Print[b <> " = " <> ToString[ToExpression[b]]]
|
||||
c = "5^(3^2)";
|
||||
Print[c <> " = " <> ToString[ToExpression[c]]]
|
||||
5
Task/Exponentiation-order/Min/exponentiation-order.min
Normal file
5
Task/Exponentiation-order/Min/exponentiation-order.min
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
5 3 2 pow pow
|
||||
"5 3 2 ^ ^ " print! puts!
|
||||
|
||||
5 3 pow 2 pow
|
||||
"5 3 ^ 2 ^ " print! puts!
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
% println 5^3^2
|
||||
15625
|
||||
% println (5^3)^2
|
||||
15625
|
||||
% println 5^(3^2)
|
||||
1953125
|
||||
7
Task/Exponentiation-order/Nim/exponentiation-order.nim
Normal file
7
Task/Exponentiation-order/Nim/exponentiation-order.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import math, sequtils
|
||||
|
||||
echo "5^3^2 = ", 5^3^2
|
||||
echo "(5^3)^2 = ", (5^3)^2
|
||||
echo "5^(3^2) = ", 5^(3^2)
|
||||
echo "foldl([5, 3, 2], a^b) = ", foldl([5, 3, 2], a^b)
|
||||
echo "foldr([5, 3, 2], a^b) = ", foldr([5, 3, 2], a^b)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# 5. ** 3. ** 2. ;;
|
||||
# 5. **( 3. ** 2.) ;;
|
||||
#(5. ** 3. ) **2. ;;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
f(s)=print(s" = "eval(s));
|
||||
apply(f, ["5^3^2", "(5^3)^2", "5^(3^2)"]);
|
||||
5
Task/Exponentiation-order/PL-I/exponentiation-order.pli
Normal file
5
Task/Exponentiation-order/PL-I/exponentiation-order.pli
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
exponentiation: procedure options(main);
|
||||
put skip edit('5**3**2 = ', 5**3**2) (A,F(7));
|
||||
put skip edit('(5**3)**2 = ', (5**3)**2) (A,F(7));
|
||||
put skip edit('5**(3**2) = ', 5**(3**2)) (A,F(7));
|
||||
end exponentiation;
|
||||
1
Task/Exponentiation-order/Perl/exponentiation-order.pl
Normal file
1
Task/Exponentiation-order/Perl/exponentiation-order.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
say "$_ = " . eval($_) for qw/5**3**2 (5**3)**2 5**(3**2)/;
|
||||
4
Task/Exponentiation-order/Phix/exponentiation-order.phix
Normal file
4
Task/Exponentiation-order/Phix/exponentiation-order.phix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
-->
|
||||
<span style="color: #0000FF;">?<span style="color: #7060A8;">power<span style="color: #0000FF;">(<span style="color: #7060A8;">power<span style="color: #0000FF;">(<span style="color: #000000;">5<span style="color: #0000FF;">,<span style="color: #000000;">3<span style="color: #0000FF;">)<span style="color: #0000FF;">,<span style="color: #000000;">2<span style="color: #0000FF;">)</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #7060A8;">power<span style="color: #0000FF;">(<span style="color: #000000;">5<span style="color: #0000FF;">,<span style="color: #7060A8;">power<span style="color: #0000FF;">(<span style="color: #000000;">3<span style="color: #0000FF;">,<span style="color: #000000;">2<span style="color: #0000FF;">)<span style="color: #0000FF;">)
|
||||
<!--
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
main =>
|
||||
X = 5**3**2, Y = (5**3)**2, Z = 5**(3**2),
|
||||
print("5**3**2 = "), println(X),
|
||||
print("(5**3)**2 = "), println(Y),
|
||||
print("5**(3**2) = "), print(Z).
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
: (** (** 5 3) 2)
|
||||
-> 15625
|
||||
|
||||
: (** 5 (** 3 2))
|
||||
-> 1953125
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
OpenConsole()
|
||||
PrintN("(5^3)^2 = " + Str(Pow(Pow(5, 3), 2)))
|
||||
PrintN("5^(3^2) = " + Str(Pow(5, (Pow(3, 2)))))
|
||||
CloseConsole()
|
||||
13
Task/Exponentiation-order/Python/exponentiation-order.py
Normal file
13
Task/Exponentiation-order/Python/exponentiation-order.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
>>> 5**3**2
|
||||
1953125
|
||||
>>> (5**3)**2
|
||||
15625
|
||||
>>> 5**(3**2)
|
||||
1953125
|
||||
>>> # The following is not normally done
|
||||
>>> try: from functools import reduce # Py3K
|
||||
except: pass
|
||||
|
||||
>>> reduce(pow, (5, 3, 2))
|
||||
15625
|
||||
>>>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
PRINT "5^3^2 ="; 5^3^2
|
||||
PRINT "(5^3)^2 ="; (5^3)^2
|
||||
PRINT "5^(3^2) ="; 5^(3^2)
|
||||
END
|
||||
2
Task/Exponentiation-order/R/exponentiation-order-1.r
Normal file
2
Task/Exponentiation-order/R/exponentiation-order-1.r
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print(quote(5**3))
|
||||
print(quote(5^3))
|
||||
1
Task/Exponentiation-order/R/exponentiation-order-2.r
Normal file
1
Task/Exponentiation-order/R/exponentiation-order-2.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
'^'('^'(5, 3), 2)
|
||||
1
Task/Exponentiation-order/R/exponentiation-order-3.r
Normal file
1
Task/Exponentiation-order/R/exponentiation-order-3.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
'^'(5, '^'(3, 2))
|
||||
2
Task/Exponentiation-order/R/exponentiation-order-4.r
Normal file
2
Task/Exponentiation-order/R/exponentiation-order-4.r
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
inputs <- alist(5^3^2, (5^3)^2, 5^(3^2), 5**3**2, (5**3)**2, 5**(3**2))
|
||||
invisible(sapply(inputs, function(x) cat(deparse(x), "returns: ", eval(x), "\n")))
|
||||
2
Task/Exponentiation-order/R/exponentiation-order-5.r
Normal file
2
Task/Exponentiation-order/R/exponentiation-order-5.r
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print(matrix(sapply(inputs, eval), dimnames = list(inputs, "Outputs")))
|
||||
print(data.frame(Inputs = sapply(inputs, deparse), Outputs = sapply(inputs, eval))))
|
||||
11
Task/Exponentiation-order/REXX/exponentiation-order.rexx
Normal file
11
Task/Exponentiation-order/REXX/exponentiation-order.rexx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/*REXX program demonstrates various ways of multiple exponentiations. */
|
||||
/*┌────────────────────────────────────────────────────────────────────┐
|
||||
│ The REXX language uses ** for exponentiation. │
|
||||
│ Also, * * can be used. │
|
||||
| and even */*power of*/* |
|
||||
└────────────────────────────────────────────────────────────────────┘*/
|
||||
|
||||
say ' 5**3**2 ───► ' 5**3**2
|
||||
say ' (5**3)**2 ───► ' (5**3)**2
|
||||
say ' 5**(3**2) ───► ' 5**(3**2)
|
||||
/*stick a fork in it, we're done.*/
|
||||
22
Task/Exponentiation-order/Racket/exponentiation-order.rkt
Normal file
22
Task/Exponentiation-order/Racket/exponentiation-order.rkt
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#lang racket
|
||||
;; 5**3**2 depends on associativity of ** : Racket's (scheme's) prefix function
|
||||
;; calling syntax only allows for pairs of arguments for expt.
|
||||
|
||||
;; So no can do for 5**3**2
|
||||
;; (5**3)**2
|
||||
(displayln "prefix")
|
||||
(expt (expt 5 3) 2)
|
||||
;; (5**3)**2
|
||||
(expt 5 (expt 3 2))
|
||||
|
||||
;; There is also a less-used infix operation (for all functions, not just expt)... which I suppose
|
||||
;; might do with an airing. But fundamentally nothing changes.
|
||||
(displayln "\"in\"fix")
|
||||
((5 . expt . 3) . expt . 2)
|
||||
(5 . expt . (3 . expt . 2))
|
||||
|
||||
;; everyone's doing a reduction, it seems
|
||||
(displayln "reduction")
|
||||
(require (only-in srfi/1 reduce reduce-right))
|
||||
(reduce expt 1 '(5 3 2))
|
||||
(reduce-right expt 1 '(5 3 2))
|
||||
14
Task/Exponentiation-order/Raku/exponentiation-order.raku
Normal file
14
Task/Exponentiation-order/Raku/exponentiation-order.raku
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use MONKEY-SEE-NO-EVAL;
|
||||
sub demo($x) { say " $x\t───► ", EVAL $x }
|
||||
|
||||
demo '5**3**2'; # show ** is right associative
|
||||
demo '(5**3)**2';
|
||||
demo '5**(3**2)';
|
||||
|
||||
demo '[**] 5,3,2'; # reduction form, show only final result
|
||||
demo '[\**] 5,3,2'; # triangle reduction, show growing results
|
||||
|
||||
# Unicode postfix exponents are supported as well:
|
||||
|
||||
demo '(5³)²';
|
||||
demo '5³²';
|
||||
16
Task/Exponentiation-order/Red/exponentiation-order.red
Normal file
16
Task/Exponentiation-order/Red/exponentiation-order.red
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
Red["Exponentiation order"]
|
||||
|
||||
exprs: [
|
||||
[5 ** 3 ** 2]
|
||||
[(5 ** 3) ** 2]
|
||||
[5 ** (3 ** 2)]
|
||||
[power power 5 3 2] ;-- functions too
|
||||
[power 5 power 3 2]
|
||||
]
|
||||
|
||||
foreach expr exprs [
|
||||
print [mold/only expr "=" do expr]
|
||||
if find expr '** [
|
||||
print [mold/only expr "=" math expr "using math"]
|
||||
]
|
||||
]
|
||||
2
Task/Exponentiation-order/Ring/exponentiation-order.ring
Normal file
2
Task/Exponentiation-order/Ring/exponentiation-order.ring
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
see "(5^3)^2 =>" + pow(pow(5,3),2) + nl
|
||||
see "5^(3^2) =>" + pow(5,pow(3,2)) + nl
|
||||
2
Task/Exponentiation-order/Ruby/exponentiation-order.rb
Normal file
2
Task/Exponentiation-order/Ruby/exponentiation-order.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ar = ["5**3**2", "(5**3)**2", "5**(3**2)", "[5,3,2].inject(:**)"]
|
||||
ar.each{|exp| puts "#{exp}:\t#{eval exp}"}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
print "5^3^2 = "; 5^3^2
|
||||
print "(5^3)^2 = "; (5^3)^2
|
||||
print "5^(3^2) = "; 5^(3^2)
|
||||
end
|
||||
5
Task/Exponentiation-order/Rust/exponentiation-order.rust
Normal file
5
Task/Exponentiation-order/Rust/exponentiation-order.rust
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
fn main() {
|
||||
println!("5**3**2 = {:7}", 5u32.pow(3).pow(2));
|
||||
println!("(5**3)**2 = {:7}", (5u32.pow(3)).pow(2));
|
||||
println!("5**(3**2) = {:7}", 5u32.pow(3u32.pow(2)));
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
writeln("5**3**2 = " <& 5**3**2);
|
||||
writeln("(5**3)**2 = " <& (5**3)**2);
|
||||
writeln("5**(3**2) = " <& 5**(3**2));
|
||||
end func;
|
||||
13
Task/Exponentiation-order/Sidef/exponentiation-order.sidef
Normal file
13
Task/Exponentiation-order/Sidef/exponentiation-order.sidef
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
var a = [
|
||||
'5**3**2',
|
||||
'(5**3)**2',
|
||||
'5**(3**2)',
|
||||
'5 ** 3 ** 2',
|
||||
'5 ** 3**2',
|
||||
'5**3 ** 2',
|
||||
'[5,3,2]«**»',
|
||||
]
|
||||
|
||||
a.each {|e|
|
||||
"%-12s == %s\n".printf(e, eval(e))
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
OutText("5** 3 **2: "); OutInt(5** 3 **2, 0); Outimage;
|
||||
OutText("(5**3)**2: "); OutInt((5**3)**2, 0); Outimage;
|
||||
OutText("5**(3**2): "); OutInt(5**(3**2), 0); Outimage
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
10 PRINT "5**3**2 = ";5**3**2
|
||||
20 PRINT "(5**3)**2 = ";(5**3)**2
|
||||
30 PRINT "5**(3**2) = ";5**(3**2)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Transcript show:'5**3**2 => '; showCR: 5**3**2.
|
||||
Transcript show:'(5**3)**2 => '; showCR: (5**3)**2.
|
||||
Transcript show:'5**(3**2) => '; showCR: 5**(3**2).
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
. di (5^3^2)
|
||||
15625
|
||||
|
||||
. di ((5^3)^2)
|
||||
15625
|
||||
|
||||
. di (5^(3^2))
|
||||
1953125
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
. mata (5^3^2)
|
||||
15625
|
||||
|
||||
. mata ((5^3)^2)
|
||||
15625
|
||||
|
||||
. mata (5^(3^2))
|
||||
1953125
|
||||
37
Task/Exponentiation-order/Swift/exponentiation-order.swift
Normal file
37
Task/Exponentiation-order/Swift/exponentiation-order.swift
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
precedencegroup ExponentiationPrecedence {
|
||||
associativity: left
|
||||
higherThan: MultiplicationPrecedence
|
||||
}
|
||||
|
||||
infix operator ** : ExponentiationPrecedence
|
||||
|
||||
@inlinable
|
||||
public func ** <T: BinaryInteger>(lhs: T, rhs: T) -> T {
|
||||
guard lhs != 0 else {
|
||||
return 1
|
||||
}
|
||||
|
||||
var x = lhs
|
||||
var n = rhs
|
||||
var y = T(1)
|
||||
|
||||
while n > 1 {
|
||||
switch n & 1 {
|
||||
case 0:
|
||||
n /= 2
|
||||
case 1:
|
||||
y *= x
|
||||
n = (n - 1) / 2
|
||||
case _:
|
||||
fatalError()
|
||||
}
|
||||
|
||||
x *= x
|
||||
}
|
||||
|
||||
return x * y
|
||||
}
|
||||
|
||||
print(5 ** 3 ** 2)
|
||||
print((5 ** 3) ** 2)
|
||||
print(5 ** (3 ** 2))
|
||||
3
Task/Exponentiation-order/Tcl/exponentiation-order.tcl
Normal file
3
Task/Exponentiation-order/Tcl/exponentiation-order.tcl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
foreach expression {5**3**2 (5**3)**2 5**(3**2)} {
|
||||
puts "${expression}:\t[expr $expression]"
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
PRINT "5^3^2 ="; 5^3^2
|
||||
PRINT "(5^3)^2 ="; (5^3)^2
|
||||
PRINT "5^(3^2) ="; 5^(3^2)
|
||||
END
|
||||
5
Task/Exponentiation-order/VBA/exponentiation-order.vba
Normal file
5
Task/Exponentiation-order/VBA/exponentiation-order.vba
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Public Sub exp()
|
||||
Debug.Print "5^3^2", 5 ^ 3 ^ 2
|
||||
Debug.Print "(5^3)^2", (5 ^ 3) ^ 2
|
||||
Debug.Print "5^(3^2)", 5 ^ (3 ^ 2)
|
||||
End Sub
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
WScript.StdOut.WriteLine "5^3^2 => " & 5^3^2
|
||||
WScript.StdOut.WriteLine "(5^3)^2 => " & (5^3)^2
|
||||
WScript.StdOut.WriteLine "5^(3^2) => " & 5^(3^2)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// Exponentiation order example:
|
||||
|
||||
@SAY "5**3**2 = " ( 5**3**2 );
|
||||
@SAY "(5**3)**2 = " ( (5**3)**2 );
|
||||
@SAY "5**(3**2) = " ( 5**(3**2) );
|
||||
|
||||
/] Output:
|
||||
|
||||
5**3**2 = 1953125
|
||||
(5**3)**2 = 15625
|
||||
5**(3**2) = 1953125
|
||||
7
Task/Exponentiation-order/Wren/exponentiation-order.wren
Normal file
7
Task/Exponentiation-order/Wren/exponentiation-order.wren
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import "./fmt" for Fmt
|
||||
|
||||
var ops = [ "5**3**2", "(5**3)**2", "5**(3**2)" ]
|
||||
var results = [ 5.pow(3).pow(2), (5.pow(3)).pow(2), 5.pow(3.pow(2)) ]
|
||||
for (i in 0...ops.count) {
|
||||
Fmt.print("$-9s -> $d", ops[i], results[i])
|
||||
}
|
||||
11
Task/Exponentiation-order/XBasic/exponentiation-order.basic
Normal file
11
Task/Exponentiation-order/XBasic/exponentiation-order.basic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
PROGRAM "Exponentiation order"
|
||||
VERSION "0.0000"
|
||||
|
||||
DECLARE FUNCTION Entry ()
|
||||
|
||||
FUNCTION Entry ()
|
||||
PRINT "5^3^2 ="; 5**3**2
|
||||
PRINT "(5^3)^2 ="; (5**3)**2
|
||||
PRINT "5^(3^2) ="; 5**(3**2)
|
||||
END FUNCTION
|
||||
END PROGRAM
|
||||
5
Task/Exponentiation-order/XPL0/exponentiation-order.xpl0
Normal file
5
Task/Exponentiation-order/XPL0/exponentiation-order.xpl0
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[Format(1, 0);
|
||||
Text(0, "5**3**2 = "); RlOut(0, Pow(5., Pow(3., 2.))); CrLf(0); \right associative
|
||||
Text(0, "(5**3)**2 = "); RlOut(0, Pow(Pow(5., 3.), 2.)); CrLf(0);
|
||||
Text(0, "5**(3**2) = "); RlOut(0, Pow(5., Pow(3., 2.))); CrLf(0);
|
||||
]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
print "5^3^2 = ", 5^3^2
|
||||
print "(5^3)^2 = ", (5^3)^2
|
||||
print "5^(3^2) = ", 5^(3^2)
|
||||
end
|
||||
3
Task/Exponentiation-order/Zkl/exponentiation-order.zkl
Normal file
3
Task/Exponentiation-order/Zkl/exponentiation-order.zkl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
println("5 ^ 3 ^ 2 = %,d".fmt((5.0).pow((3.0).pow(2))));
|
||||
println("(5 ^ 3) ^ 2 = %,d".fmt((5.0).pow(3).pow(2)));
|
||||
println("5 ^ (3 ^ 2) = %,d".fmt((5.0).pow((3.0).pow(2))));
|
||||
Loading…
Add table
Add a link
Reference in a new issue