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
|
|
@ -0,0 +1,8 @@
|
|||
;; copied from Racket
|
||||
|
||||
(for*/list ([x (in-range 1 21)]
|
||||
[y (in-range x 21)]
|
||||
[z (in-range y 21)])
|
||||
#:when (= (+ (* x x) (* y y)) (* z z))
|
||||
(list x y z))
|
||||
→ ((3 4 5) (5 12 13) (6 8 10) (8 15 17) (9 12 15) (12 16 20))
|
||||
3
Task/List-comprehensions/FunL/list-comprehensions.funl
Normal file
3
Task/List-comprehensions/FunL/list-comprehensions.funl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def triples( n ) = [(a, b, c) | a <- 1..n-2, b <- a+1..n-1, c <- b+1..n if a^2 + b^2 == c^2]
|
||||
|
||||
println( triples(20) )
|
||||
11
Task/List-comprehensions/Lasso/list-comprehensions-1.lasso
Normal file
11
Task/List-comprehensions/Lasso/list-comprehensions-1.lasso
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/lasso9
|
||||
|
||||
local(n = 20)
|
||||
local(triples =
|
||||
with x in generateSeries(1, #n),
|
||||
y in generateSeries(#x, #n),
|
||||
z in generateSeries(#y, #n)
|
||||
where #x*#x + #y*#y == #z*#z
|
||||
select (:#x, #y, #z)
|
||||
)
|
||||
#triples->join('\n')
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
staticarray(3, 4, 5)
|
||||
staticarray(5, 12, 13)
|
||||
staticarray(6, 8, 10)
|
||||
staticarray(8, 15, 17)
|
||||
staticarray(9, 12, 15)
|
||||
staticarray(12, 16, 20)
|
||||
50
Task/List-comprehensions/Nim/list-comprehensions.nim
Normal file
50
Task/List-comprehensions/Nim/list-comprehensions.nim
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import macros
|
||||
|
||||
type ListComprehension = object
|
||||
var lc*: ListComprehension
|
||||
|
||||
macro `[]`*(lc: ListComprehension, x, t): expr =
|
||||
expectLen(x, 3)
|
||||
expectKind(x, nnkInfix)
|
||||
expectKind(x[0], nnkIdent)
|
||||
assert($x[0].ident == "|")
|
||||
|
||||
result = newCall(
|
||||
newDotExpr(
|
||||
newIdentNode("result"),
|
||||
newIdentNode("add")),
|
||||
x[1])
|
||||
|
||||
for i in countdown(x[2].len-1, 0):
|
||||
let y = x[2][i]
|
||||
expectKind(y, nnkInfix)
|
||||
expectMinLen(y, 1)
|
||||
if y[0].kind == nnkIdent and $y[0].ident == "<-":
|
||||
expectLen(y, 3)
|
||||
result = newNimNode(nnkForStmt).add(y[1], y[2], result)
|
||||
else:
|
||||
result = newIfStmt((y, result))
|
||||
|
||||
result = newNimNode(nnkCall).add(
|
||||
newNimNode(nnkPar).add(
|
||||
newNimNode(nnkLambda).add(
|
||||
newEmptyNode(),
|
||||
newEmptyNode(),
|
||||
newEmptyNode(),
|
||||
newNimNode(nnkFormalParams).add(
|
||||
newNimNode(nnkBracketExpr).add(
|
||||
newIdentNode("seq"),
|
||||
t)),
|
||||
newEmptyNode(),
|
||||
newEmptyNode(),
|
||||
newStmtList(
|
||||
newAssignment(
|
||||
newIdentNode("result"),
|
||||
newNimNode(nnkPrefix).add(
|
||||
newIdentNode("@"),
|
||||
newNimNode(nnkBracket))),
|
||||
result))))
|
||||
|
||||
const n = 20
|
||||
echo lc[(x,y,z) | (x <- 1..n, y <- x..n, z <- y..n, x*x + y*y == z*z),
|
||||
tuple[a,b,c: int]]
|
||||
8
Task/List-comprehensions/Ring/list-comprehensions.ring
Normal file
8
Task/List-comprehensions/Ring/list-comprehensions.ring
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
for x = 1 to 20
|
||||
for y = x to 20
|
||||
for z = y to 20
|
||||
if pow(x,2) + pow(y,2) = pow(z,2)
|
||||
see "[" + x + "," + y + "," + z + "]" + nl ok
|
||||
next
|
||||
next
|
||||
next
|
||||
10
Task/List-comprehensions/Sidef/list-comprehensions.sidef
Normal file
10
Task/List-comprehensions/Sidef/list-comprehensions.sidef
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
var n = 20
|
||||
say gather {
|
||||
for x in (1 .. n) {
|
||||
for y in (x .. n) {
|
||||
for z in (y .. n) {
|
||||
take([x,y,z]) if (x*x + y*y == z*z)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
4
Task/List-comprehensions/jq/list-comprehensions-1.jq
Normal file
4
Task/List-comprehensions/jq/list-comprehensions-1.jq
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
def triples(n):
|
||||
range(1;n+1) as $x | range($x;n+1) as $y | range($y;n+1) as $z
|
||||
| select($x*$x + $y*$y == $z*$z)
|
||||
| [$x, $y, $z] ;
|
||||
10
Task/List-comprehensions/jq/list-comprehensions-2.jq
Normal file
10
Task/List-comprehensions/jq/list-comprehensions-2.jq
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# listof( stream; criterion) constructs an array of those
|
||||
# elements in the stream that satisfy the criterion
|
||||
def listof( stream; criterion): [ stream|select(criterion) ];
|
||||
|
||||
def listof_triples(n):
|
||||
listof( range(1;n+1) as $x | range($x;n+1) as $y | range($y;n+1) as $z
|
||||
| [$x, $y, $z];
|
||||
.[0] * .[0] + .[1] * .[1] == .[2] * .[2] ) ;
|
||||
|
||||
listof_triples(20)
|
||||
Loading…
Add table
Add a link
Reference in a new issue