Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,22 @@
!Trabb Pardo-Knuth algorithm
PROGRAM TPK
!VAR I%,Y
DIM A[10]
FUNCTION F(T)
F=SQR(ABS(T))+5*T^3
END FUNCTION
BEGIN
DATA(10,-1,1,2,3,4,4.3,4.305,4.303,4.302,4.301)
FOR I%=0 TO 10 DO
READ(A[I%])
END FOR
FOR I%=10 TO 0 STEP -1 DO
Y=F(A[I%])
PRINT("F(";A[I%];")=";)
IF Y>400 THEN PRINT("--->too large<---")
ELSE PRINT(Y)
END IF
END FOR
END PROGRAM

View file

@ -0,0 +1,18 @@
(define (trabb-fun n)
(+ (* 5 n n n) (sqrt(abs n))))
(define (check-trabb n)
(if (number? n)
(if (<= (trabb-fun n) 400)
(printf "🌱 f(%d) = %d" n (trabb-fun n))
(printf "❌ f(%d) = %d" n (trabb-fun n)))
(error "not a number" n)))
(define (trabb (numlist null))
(while (< (length numlist) 11)
(set! numlist (append numlist
(or
(read default: (shuffle (iota 11))
prompt: (format "Please enter %d more numbers" (- 11 (length numlist))))
(error 'incomplete-list numlist))))) ;; users cancel
(for-each check-trabb (reverse (take numlist 11))))

View file

@ -0,0 +1,20 @@
(trabb)
;; input : (0 4 1 8 5 9 10 3 6 7 2)
🌱 f(2) = 41.41421356237309
❌ f(7) = 1717.6457513110645
❌ f(6) = 1082.4494897427833
🌱 f(3) = 136.73205080756887
❌ f(10) = 5003.162277660168
❌ f(9) = 3648
❌ f(5) = 627.2360679774998
❌ f(8) = 2562.828427124746
🌱 f(1) = 6
🌱 f(4) = 322
🌱 f(0) = 0
;; extra credit : let's find the threshold
(lib 'math)
(define (g x) (- (trabb-fun x) 400))
(root g 0 10)
→ 4.301409367213084

View file

@ -0,0 +1,35 @@
' version 22-10-2016
' compile with: fbc -s console
Function f(n As Double) As Double
return Sqr(Abs(n)) + 5 * n ^ 5
End Function
' ------=< MAIN >=------
Dim As Double x, s(0 To 10)
Dim As Long i
For i = 0 To 10
Print Str(i);
Input " => ", s(i)
Next
Print
Print String(20,"-")
For i = 10 To 0 Step -1
Print "f(" + Str(s(i)) + ") = ";
x = f(s(i))
If x > 400 Then
Print "-=< to large >=-"
Else
Print x
End If
Next
' empty keyboard buffer
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End

View file

@ -0,0 +1,13 @@
import math, rdstdin, strutils, algorithm
proc f(x): float = x.abs.pow(0.5) + 5 * x.pow(3)
proc ask: seq[float] =
readLineFromStdin("\n11 numbers: ").strip.split[0..10].map(parseFloat)
var s = ask()
reverse s
for x in s:
let result = f x
stdout.write " ",x,":", if result > 400: "TOO LARGE!" else: $result
echo ""

View file

@ -0,0 +1,12 @@
decimals(7)
s = [4,3,4,2,1,1,2,3,4,5]
for i = 10 to 1 step -1
see "f(" + s[i] + ")=";
x = f(s[i])
if x > 400 see "--- too large ---" + nl
else see x + nl ok
next
func f n
return sqrt(fabs(n))+5*pow(n,3)

View file

@ -0,0 +1,8 @@
var nums; do {
nums = Sys.readln("Please type 11 space-separated numbers: ").nums
} while(nums.len != 11)
nums.reverse.each { |n|
var r = (n.abs.sqrt + (5 * n**3));
say "#{n}\t#{ r > 400 ? 'Urk!' : r }";
}

View file

@ -0,0 +1,18 @@
import Foundation
print("Enter 11 numbers for the Trabb─Pardo─Knuth algorithm:")
let f: (Double) -> Double = { sqrt(fabs($0)) + 5 * pow($0, 3) }
(1...11)
.generate()
.map { i -> Double in
print("\(i): ", terminator: "")
guard let s = readLine(), let n = Double(s) else { return 0 }
return n
}
.reverse()
.forEach {
let result = f($0)
print("f(\($0))", result > 400.0 ? "OVERFLOW" : result, separator: "\t")
}

View file

@ -0,0 +1,37 @@
|Trabb PardoKnuth algorithm
a : 11 0
i
if i LE 10
[] $s
~ $s w
w a.i
+ i
goif
endif
10 i
if i GE 0
call f
if x GT 400
'too large' $s
else
~ x $s
endif
~ i $r
+ ' ' $r
+ $r $s.1
$s []
- i
goif
endif
stop
f a.i t
* t t x
* x t x
* 5 x
abs t
sqrt t y
+ y x
return

View file

@ -0,0 +1,11 @@
def f:
def abs: if . < 0 then -. else . end;
def power(x): (x * log) | exp;
. as $x | abs | power(0.5) + (5 * (.*.*. ));
. as $in | split(" ") | map(tonumber)
| if length == 11 then
reverse | map(f | if . > 400 then "TOO LARGE" else . end)
else error("The number of numbers was not 11.")
end
| .[] # print one result per line

View file

@ -0,0 +1,15 @@
$ echo "Enter 11 numbers on one line; when done, enter the end-of-file character:" ;\
jq -M -s -R -f Trabb_Pardo-Knuth_algorithm.jq
> Enter 11 numbers on one line; when done, enter the end-of-file character:
1 2 3 4 5 6 7 8 9 10 11
"TOO LARGE"
"TOO LARGE"
"TOO LARGE"
"TOO LARGE"
"TOO LARGE"
"TOO LARGE"
"TOO LARGE"
322
136.73205080756887
41.41421356237309
6