Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
31
Task/Arithmetic-Integer/ECL/arithmetic-integer.ecl
Normal file
31
Task/Arithmetic-Integer/ECL/arithmetic-integer.ecl
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
ArithmeticDemo(INTEGER A,INTEGER B) := FUNCTION
|
||||
ADDit := A + B;
|
||||
SUBTRACTit := A - B;
|
||||
MULTIPLYit := A * B;
|
||||
INTDIVIDEit := A DIV B; //INTEGER DIVISION
|
||||
DIVIDEit := A / B; //standard division
|
||||
Remainder := A % B;
|
||||
EXPit := POWER(A,B);
|
||||
DS := DATASET([{A,B,'A PLUS B is:',ADDit},
|
||||
{A,B,'A MINUS B is:',SUBTRACTit},
|
||||
{A,B,'A TIMES B is:',MULTIPLYit},
|
||||
{A,B,'A INT DIVIDE BY B is:',INTDIVIDEit},
|
||||
{A,B,'REMAINDER is:',Remainder},
|
||||
{A,B,'A DIVIDE BY B is:',DIVIDEit},
|
||||
{A,B,'A RAISED TO B:',EXPit}],
|
||||
{INTEGER AVal,INTEGER BVal,STRING18 valuetype,STRING val});
|
||||
|
||||
RETURN DS;
|
||||
END;
|
||||
|
||||
ArithmeticDemo(1,1);
|
||||
ArithmeticDemo(2,2);
|
||||
ArithmeticDemo(50,5);
|
||||
ArithmeticDemo(10,3);
|
||||
ArithmeticDemo(-1,2);
|
||||
|
||||
/* NOTE:Division by zero defaults to generating a zero result (0),
|
||||
rather than reporting a “divide by zero” error.
|
||||
This avoids invalid or unexpected data aborting a long job.
|
||||
This default behavior can be changed
|
||||
*/
|
||||
19
Task/Arithmetic-Integer/ERRE/arithmetic-integer.erre
Normal file
19
Task/Arithmetic-Integer/ERRE/arithmetic-integer.erre
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
PROGRAM INTEGER_ARITHMETIC
|
||||
|
||||
!
|
||||
! for rosettacode.org
|
||||
!
|
||||
|
||||
!$INTEGER
|
||||
|
||||
BEGIN
|
||||
INPUT("Enter a number ",A)
|
||||
INPUT("Enter another number ",B)
|
||||
|
||||
PRINT("Addition ";A;"+";B;"=";(A+B))
|
||||
PRINT("Subtraction ";A;"-";B;"=";(A-B))
|
||||
PRINT("Multiplication ";A;"*";B;"=";(A*B))
|
||||
PRINT("Integer division ";A;"div";B;"=";(A DIV B))
|
||||
PRINT("Remainder or modulo ";A;"mod";B;"=";(A MOD B))
|
||||
PRINT("Power ";A;"^";B;"=";(A^B))
|
||||
END PROGRAM
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Dim As Integer i, j
|
||||
Input "Enter two integers separated by a comma"; i, j
|
||||
Print i;" + "; j; " = "; i + j
|
||||
Print i;" - "; j; " = "; i - j
|
||||
Print i;" * "; j; " = "; i * j
|
||||
Print i;" / "; j; " = "; i \ j
|
||||
Print i;" % "; j; " = "; i Mod j
|
||||
Print i;" ^ "; j; " = "; i ^ j
|
||||
Sleep
|
||||
|
||||
' Integer division (for which FB uses the '\' operator) rounds towards zero
|
||||
|
||||
' Remainder (for which FB uses the Mod operator) will, if non-zero, match the sign
|
||||
' of the first operand
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
include "ConsoleWindow"
|
||||
|
||||
dim as Str31 a, b
|
||||
dim as long i1, i2
|
||||
|
||||
input "Enter the first integer: "; a
|
||||
print
|
||||
input "Enter the second integer: "; b
|
||||
print : print
|
||||
|
||||
i1 = val(a) : i2 = val(b)
|
||||
|
||||
print " Number 1:"; i1
|
||||
print " Number 2:"; i2
|
||||
print
|
||||
print " Add: "; i1; " +"; i2; " ="; i1 + i2
|
||||
print " Subtract: "; i1; " -"; i2; " ="; i1 - i2
|
||||
print " Multiply: "; i1; " *"; i2; " ="; i1 * i2
|
||||
|
||||
if i2 != 0
|
||||
print " Divide: "; i1; " /"; i2; " ="; i1 / i2
|
||||
print i1; " mod"; i2; " ="; i1 MOD i2; " remainder"
|
||||
print i1; " raised to power of"; i2; " ="; i1 ^ i2
|
||||
else
|
||||
print "Cannot divide by zero."
|
||||
end if
|
||||
7
Task/Arithmetic-Integer/GEORGE/arithmetic-integer.george
Normal file
7
Task/Arithmetic-Integer/GEORGE/arithmetic-integer.george
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
R (m) ;
|
||||
R (n) ;
|
||||
m n + P;
|
||||
m n - P;
|
||||
m n × P;
|
||||
m n div P;
|
||||
m n rem P;
|
||||
11
Task/Arithmetic-Integer/Harbour/arithmetic-integer.harbour
Normal file
11
Task/Arithmetic-Integer/Harbour/arithmetic-integer.harbour
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
procedure Test( a, b )
|
||||
? "a+b", a + b
|
||||
? "a-b", a - b
|
||||
? "a*b", a * b
|
||||
// The quotient isn't integer, so we use the Int() function, which truncates it downward.
|
||||
? "a/b", Int( a / b )
|
||||
// Remainder:
|
||||
? "a%b", a % b
|
||||
// Exponentiation is also a base arithmetic operation
|
||||
? "a**b", a ** b
|
||||
return
|
||||
11
Task/Arithmetic-Integer/I/arithmetic-integer.i
Normal file
11
Task/Arithmetic-Integer/I/arithmetic-integer.i
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
software {
|
||||
var a = number(read(' '))
|
||||
var b = number(read('\n'))
|
||||
|
||||
print("Sum: " , a + b)
|
||||
print("Difference: " , a - b)
|
||||
print("Product: " , a * b)
|
||||
print("Quotient: " , a / b)
|
||||
print("Modulus: " , a mod b)
|
||||
print("Exponent: " , a ^ b)
|
||||
}
|
||||
14
Task/Arithmetic-Integer/LFE/arithmetic-integer-1.lfe
Normal file
14
Task/Arithmetic-Integer/LFE/arithmetic-integer-1.lfe
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(defmodule arith
|
||||
(export all))
|
||||
|
||||
(defun demo-arith ()
|
||||
(case (: io fread '"Please enter two integers: " '"~d~d")
|
||||
((tuple 'ok (a b))
|
||||
(: io format '"~p + ~p = ~p~n" (list a b (+ a b)))
|
||||
(: io format '"~p - ~p = ~p~n" (list a b (- a b)))
|
||||
(: io format '"~p * ~p = ~p~n" (list a b (* a b)))
|
||||
(: io format '"~p^~p = ~p~n" (list a b (: math pow a b)))
|
||||
; div truncates towards zero
|
||||
(: io format '"~p div ~p = ~p~n" (list a b (div a b)))
|
||||
; rem's result takes the same sign as the first operand
|
||||
(: io format '"~p rem ~p = ~p~n" (list a b (rem a b))))))
|
||||
11
Task/Arithmetic-Integer/LFE/arithmetic-integer-2.lfe
Normal file
11
Task/Arithmetic-Integer/LFE/arithmetic-integer-2.lfe
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
> (slurp '"arith.lfe")
|
||||
#(ok arith)
|
||||
> (demo-arith)
|
||||
Please enter two integers: 2 8
|
||||
2 + 8 = 10
|
||||
2 - 8 = -6
|
||||
2 * 8 = 16
|
||||
2^8 = 256.0
|
||||
2 div 8 = 0
|
||||
2 rem 8 = 2
|
||||
ok
|
||||
8
Task/Arithmetic-Integer/Lasso/arithmetic-integer.lasso
Normal file
8
Task/Arithmetic-Integer/Lasso/arithmetic-integer.lasso
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
local(a = 6, b = 4)
|
||||
#a + #b // 10
|
||||
#a - #b // 2
|
||||
#a * #b // 24
|
||||
#a / #b // 1
|
||||
#a % #b // 2
|
||||
math_pow(#a,#b) // 1296
|
||||
math_pow(#b,#a) // 4096
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
ask "enter 2 numbers (comma separated)"
|
||||
if it is not empty then
|
||||
put item 1 of it into n1
|
||||
put item 2 of it into n2
|
||||
put sum(n1,n2) into ai["sum"]
|
||||
put n1 * n2 into ai["product"]
|
||||
put n1 div n2 into ai["quotient"] -- truncates
|
||||
put n1 mod n2 into ai["remainder"]
|
||||
put n1^n2 into ai["power"]
|
||||
combine ai using comma and colon
|
||||
put ai
|
||||
end if
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
-2,4 - power:16,product:-8,quotient:0,remainder:-2,sum:2
|
||||
2,-4 - power:0.0625,product:-8,quotient:0,remainder:2,sum:-2
|
||||
-2,-4 - power:0.0625,product:8,quotient:0,remainder:-2,sum:-6
|
||||
2,4 - power:16,product:8,quotient:0,remainder:2,sum:6
|
||||
11,4 - power:14641,product:44,quotient:2,remainder:3,sum:15
|
||||
22
Task/Arithmetic-Integer/Nim/arithmetic-integer.nim
Normal file
22
Task/Arithmetic-Integer/Nim/arithmetic-integer.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import parseopt,strutils
|
||||
|
||||
var
|
||||
opt: TOptParser = initOptParser()
|
||||
str = opt.cmdLineRest.split
|
||||
a: int = 0
|
||||
b: int = 0
|
||||
|
||||
try:
|
||||
a = parseInt(str[0])
|
||||
b = parseInt(str[1])
|
||||
except EinvalidValue:
|
||||
quit("Invalid params. Two integers are expected.")
|
||||
|
||||
|
||||
echo ("a : " & $a)
|
||||
echo ("b : " & $b)
|
||||
echo ("a + b : " & $(a+b))
|
||||
echo ("a - b : " & $(a-b))
|
||||
echo ("a * b : " & $(a*b))
|
||||
echo ("a div b: " & $(a div b))
|
||||
echo ("a mod b: " & $(a mod b))
|
||||
7
Task/Arithmetic-Integer/Oforth/arithmetic-integer.oforth
Normal file
7
Task/Arithmetic-Integer/Oforth/arithmetic-integer.oforth
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
: integers(a, b)
|
||||
"a + b =" . a b + .cr
|
||||
"a - b =" . a b - .cr
|
||||
"a * b =" . a b * .cr
|
||||
"a / b =" . a b / .cr
|
||||
"a mod b =" . a b mod .cr
|
||||
"a pow b =" . a b pow .cr ;
|
||||
19
Task/Arithmetic-Integer/PHL/arithmetic-integer.phl
Normal file
19
Task/Arithmetic-Integer/PHL/arithmetic-integer.phl
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
module arith;
|
||||
|
||||
extern printf;
|
||||
extern scanf;
|
||||
|
||||
@Integer main [
|
||||
@Pointer<@Integer> a = alloc(4);
|
||||
@Pointer<@Integer> b = alloc(4);
|
||||
scanf("%i %i", a, b);
|
||||
|
||||
printf("a + b = %i\n", a::get + b::get);
|
||||
printf("a - b = %i\n", a::get - b::get);
|
||||
printf("a * b = %i\n", a::get * b::get);
|
||||
printf("a / b = %i\n", a::get / b::get);
|
||||
printf("a % b = %i\n", a::get % b::get);
|
||||
printf("a ** b = %i\n", a::get ** b::get);
|
||||
|
||||
return 0;
|
||||
]
|
||||
1
Task/Arithmetic-Integer/Panda/arithmetic-integer.panda
Normal file
1
Task/Arithmetic-Integer/Panda/arithmetic-integer.panda
Normal file
|
|
@ -0,0 +1 @@
|
|||
a=3 b=7 func:_bbf__number_number_number =>f.name.<b> '(' a b ')' ' => ' f(a b) nl
|
||||
9
Task/Arithmetic-Integer/Phix/arithmetic-integer.phix
Normal file
9
Task/Arithmetic-Integer/Phix/arithmetic-integer.phix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
integer a = floor(prompt_number("a = ",{}))
|
||||
integer b = floor(prompt_number("b = ",{}))
|
||||
|
||||
printf(1,"a + b = %d\n", a+b)
|
||||
printf(1,"a - b = %d\n", a-b)
|
||||
printf(1,"a * b = %d\n", a*b)
|
||||
printf(1,"a / b = %g\n", a/b) -- does not truncate
|
||||
printf(1,"remainder(a,b) = %d\n", remainder(a,b)) -- same sign as first operand
|
||||
printf(1,"power(a,b) = %g\n", power(a,b))
|
||||
9
Task/Arithmetic-Integer/Ring/arithmetic-integer.ring
Normal file
9
Task/Arithmetic-Integer/Ring/arithmetic-integer.ring
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
func Test a,b
|
||||
see "a+b" + ( a + b ) + nl
|
||||
see "a-b" + ( a - b ) + nl
|
||||
see "a*b" + ( a * b ) + nl
|
||||
// The quotient isn't integer, so we use the Ceil() function, which truncates it downward.
|
||||
see "a/b" + Ceil( a / b ) + nl
|
||||
// Remainder:
|
||||
see "a%b" + ( a % b ) + nl
|
||||
see "a**b" + pow(a,b ) + nl
|
||||
6
Task/Arithmetic-Integer/SSEM/arithmetic-integer-1.ssem
Normal file
6
Task/Arithmetic-Integer/SSEM/arithmetic-integer-1.ssem
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
00101000000000100000000000000000 0. -20 to c
|
||||
10100000000001100000000000000000 1. c to 5
|
||||
10100000000000100000000000000000 2. -5 to c
|
||||
10101000000000010000000000000000 3. Sub. 21
|
||||
00000000000001110000000000000000 4. Stop
|
||||
00000000000000000000000000000000 5. 0
|
||||
6
Task/Arithmetic-Integer/SSEM/arithmetic-integer-2.ssem
Normal file
6
Task/Arithmetic-Integer/SSEM/arithmetic-integer-2.ssem
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
00101000000000100000000000000000 0. -20 to c
|
||||
10101000000000010000000000000000 1. Sub. 21
|
||||
10100000000001100000000000000000 2. c to 5
|
||||
10100000000000100000000000000000 3. -5 to c
|
||||
00000000000001110000000000000000 4. Stop
|
||||
00000000000000000000000000000000 5. 0
|
||||
6
Task/Arithmetic-Integer/Sidef/arithmetic-integer.sidef
Normal file
6
Task/Arithmetic-Integer/Sidef/arithmetic-integer.sidef
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
var a = Sys.scanln("First number: ").to_i;
|
||||
var b = Sys.scanln("Second number: ").to_i;
|
||||
|
||||
%w'+ - * // % ** ^ | & << >>'.each { |op|
|
||||
"#{a} #{op} #{b} = #{a.$op(b)}".say;
|
||||
}
|
||||
17
Task/Arithmetic-Integer/Ursa/arithmetic-integer.ursa
Normal file
17
Task/Arithmetic-Integer/Ursa/arithmetic-integer.ursa
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#
|
||||
# integer arithmetic
|
||||
#
|
||||
|
||||
decl int x y
|
||||
out "number 1: " console
|
||||
set x (in int console)
|
||||
out "number 2: " console
|
||||
set y (in int console)
|
||||
|
||||
out "\nsum:\t" (int (+ x y)) endl console
|
||||
out "diff:\t" (int (- x y)) endl console
|
||||
out "prod:\t" (int (* x y)) endl console
|
||||
# quotient doesn't round at all, but the int function rounds up
|
||||
out "quot:\t" (int (/ x y)) endl console
|
||||
# mod takes the sign of x
|
||||
out "mod:\t" (int (mod x y)) endl console
|
||||
9
Task/Arithmetic-Integer/Wart/arithmetic-integer.wart
Normal file
9
Task/Arithmetic-Integer/Wart/arithmetic-integer.wart
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
a <- (read)
|
||||
b <- (read)
|
||||
prn "sum: " a+b
|
||||
prn "difference: " a-b
|
||||
prn "product: " a*b
|
||||
prn "quotient: " a/b
|
||||
prn "integer quotient: " (int a/b)
|
||||
prn "remainder: " a%b
|
||||
prn "exponent: " a^b
|
||||
8
Task/Arithmetic-Integer/Wren/arithmetic-integer.wren
Normal file
8
Task/Arithmetic-Integer/Wren/arithmetic-integer.wren
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import "io" for Stdin
|
||||
var a = Num.fromString(Stdin.readLine())
|
||||
var b = Num.fromString(Stdin.readLine())
|
||||
System.print("sum: %(a + b)")
|
||||
System.print("difference: %(a - b)")
|
||||
System.print("product: %(a * b)")
|
||||
System.print("integer quotient: %((a / b).floor)")
|
||||
System.print("remainder: %(a % b)")
|
||||
17
Task/Arithmetic-Integer/XLISP/arithmetic-integer.xlisp
Normal file
17
Task/Arithmetic-Integer/XLISP/arithmetic-integer.xlisp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(DEFUN INTEGER-ARITHMETIC ()
|
||||
(DISPLAY "Enter two integers separated by a space.")
|
||||
(NEWLINE)
|
||||
(DISPLAY "> ")
|
||||
(DEFINE A (READ))
|
||||
(DEFINE B (READ))
|
||||
(DISPLAY `(SUM ,(+ A B)))
|
||||
(NEWLINE)
|
||||
(DISPLAY `(DIFFERENCE ,(- A B)))
|
||||
(NEWLINE)
|
||||
(DISPLAY `(PRODUCT ,(* A B)))
|
||||
(NEWLINE)
|
||||
(DISPLAY `(QUOTIENT ,(QUOTIENT A B))) ; truncates towards zero
|
||||
(NEWLINE)
|
||||
(DISPLAY `(REMAINDER ,(REM A B))) ; takes sign of first operand
|
||||
(NEWLINE)
|
||||
(DISPLAY `(EXPONENTIATION ,(EXPT A B))))
|
||||
17
Task/Arithmetic-Integer/jq/arithmetic-integer.jq
Normal file
17
Task/Arithmetic-Integer/jq/arithmetic-integer.jq
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Lines which do not have two integers are skipped:
|
||||
|
||||
def arithmetic:
|
||||
split(" ") | select(length > 0) | map(tonumber)
|
||||
| if length > 1 then
|
||||
.[0] as $a | .[1] as $b
|
||||
| "For a = \($a) and b = \($b):\n" +
|
||||
"a + b = \($a + $b)\n" +
|
||||
"a - b = \($a - $b)\n" +
|
||||
"a * b = \($a * $b)\n" +
|
||||
"a/b|floor = \($a / $b | floor)\n" +
|
||||
"a % b = \($a % $b)\n" +
|
||||
"a | exp = \($a | exp)\n"
|
||||
else empty
|
||||
end ;
|
||||
|
||||
arithmetic
|
||||
Loading…
Add table
Add a link
Reference in a new issue