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
18
Task/Loops-Nested/ERRE/loops-nested.erre
Normal file
18
Task/Loops-Nested/ERRE/loops-nested.erre
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
DIM A%[10,10] ! in declaration part
|
||||
.............
|
||||
PRINT(CHR$(12);) !CLS
|
||||
FOR ROW=1 TO 10 DO
|
||||
FOR COL=1 TO 10 DO
|
||||
A%[ROW,COL]=INT(RND(1)*20)+1 ! INT and RND are ERRE predeclared functions
|
||||
! RND generates random numbers between 0 and 1
|
||||
END FOR
|
||||
END FOR
|
||||
|
||||
FOR ROW=1 TO 10 DO
|
||||
FOR COL=1 TO 10 DO
|
||||
PRINT(A%[ROW,COL])
|
||||
EXIT IF A%[ROW,COL]=20
|
||||
END FOR
|
||||
EXIT IF A%[ROW,COL]=20 ! EXIT breaks the current loop only: you must repeat it,
|
||||
! use a boolean variable or a GOTO label statement
|
||||
END FOR
|
||||
8
Task/Loops-Nested/EchoLisp/loops-nested.echolisp
Normal file
8
Task/Loops-Nested/EchoLisp/loops-nested.echolisp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(lib 'math) ;; for 2D-arrays
|
||||
(define array (build-array 42 42 (lambda(i j) (1+ (random 20)))))
|
||||
→ array
|
||||
|
||||
;;
|
||||
(for* ((row array) (aij row)) (write aij) #:break (= aij 20))
|
||||
→ 9 8 11 1 14 11 1 9 16 1 10 5 5 6 5 4 13 17 14 13 6 10 16 4 8 5 1 17 16 19 4 6 18 1 15 3 4 13 19
|
||||
6 12 5 5 17 19 16 3 7 2 15 16 14 16 16 19 18 14 16 6 18 14 17 20
|
||||
22
Task/Loops-Nested/FreeBASIC/loops-nested.freebasic
Normal file
22
Task/Loops-Nested/FreeBASIC/loops-nested.freebasic
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Randomize
|
||||
Dim a(1 To 20, 1 To 20) As Integer
|
||||
For i As Integer = 1 To 20
|
||||
For j As Integer = 1 To 20
|
||||
a(i, j) = Int(Rnd * 20) + 1
|
||||
Next j
|
||||
Next i
|
||||
|
||||
For i As Integer = 1 To 20
|
||||
For j As Integer = 1 To 20
|
||||
Print Using "##"; a(i, j);
|
||||
Print " ";
|
||||
If a(i, j) = 20 Then Exit For, For '' Exits both for loops
|
||||
Next j
|
||||
Print
|
||||
Next i
|
||||
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
21
Task/Loops-Nested/Lasso/loops-nested.lasso
Normal file
21
Task/Loops-Nested/Lasso/loops-nested.lasso
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
local(a) = array(
|
||||
array(2, 12, 10, 4),
|
||||
array(18, 11, 9, 3),
|
||||
array(14, 15, 7, 17),
|
||||
array(6, 19, 8, 13),
|
||||
array(1, 20, 16, 5)
|
||||
)
|
||||
|
||||
// Query expression
|
||||
with i in delve(#a) do {
|
||||
stdoutnl(#i)
|
||||
#i == 20 ? return
|
||||
}
|
||||
|
||||
// Nested loops
|
||||
#a->foreach => {
|
||||
#1->foreach => {
|
||||
stdoutnl(#1)
|
||||
#1 == 20 ? return
|
||||
}
|
||||
}
|
||||
18
Task/Loops-Nested/Lingo/loops-nested.lingo
Normal file
18
Task/Loops-Nested/Lingo/loops-nested.lingo
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
-- create two-dimensional array with random numbers
|
||||
a = []
|
||||
repeat with i = 1 to 20
|
||||
a[i] = []
|
||||
repeat with j = 1 to 20
|
||||
a[i][j] = random(20)
|
||||
end repeat
|
||||
end repeat
|
||||
|
||||
-- iterate over rows and columns, print value, exit both loops if it's 20
|
||||
repeat with i = 1 to 20
|
||||
repeat with j = 1 to 20
|
||||
v = a[i][j]
|
||||
put v
|
||||
if v=20 then exit repeat
|
||||
end repeat
|
||||
if v=20 then exit repeat
|
||||
end repeat
|
||||
21
Task/Loops-Nested/LiveCode/loops-nested.livecode
Normal file
21
Task/Loops-Nested/LiveCode/loops-nested.livecode
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
repeat with i = 1 to 10
|
||||
repeat with j = 1 to 10
|
||||
put random(20) into aNums[i,j]
|
||||
end repeat
|
||||
end repeat
|
||||
|
||||
repeat with i = 1 to 10
|
||||
repeat with j = 1 to 10
|
||||
if aNums[i,j] = 20 then
|
||||
put true into exitLoop
|
||||
exit repeat
|
||||
end if
|
||||
end repeat
|
||||
if exitLoop then exit repeat
|
||||
end repeat
|
||||
|
||||
if exitLoop then
|
||||
put "20 found in" && i & comma & j
|
||||
else
|
||||
put "20 not found"
|
||||
end if
|
||||
24
Task/Loops-Nested/Nim/loops-nested.nim
Normal file
24
Task/Loops-Nested/Nim/loops-nested.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import math, strutils
|
||||
|
||||
const arrSize = 10
|
||||
|
||||
var a: array[0..arrSize-1, array[0..arrSize-1, int]]
|
||||
var s: string = ""
|
||||
|
||||
randomize() # different results each time this runs
|
||||
|
||||
for i in 0 .. arrSize-1:
|
||||
for j in countup(0,arrSize-1):
|
||||
a[i][j] = random(20)+1
|
||||
|
||||
block outer:
|
||||
for i in countup(0,arrSize-1):
|
||||
for j in 0 .. arrSize-1:
|
||||
if a[i][j] < 10:
|
||||
s.add(" ")
|
||||
addf(s,"$#",$a[i][j])
|
||||
if a[i][j] == 20:
|
||||
break outer
|
||||
s.add(", ")
|
||||
s.add("\n")
|
||||
echo(s)
|
||||
14
Task/Loops-Nested/Phix/loops-nested-1.phix
Normal file
14
Task/Loops-Nested/Phix/loops-nested-1.phix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
constant s = sq_rand(repeat(repeat(20,20),20))
|
||||
integer found = 0
|
||||
for i=1 to 20 do
|
||||
for j=1 to 20 do
|
||||
printf(1,"%d",s[i][j])
|
||||
if s[i][j]=20 then
|
||||
found = 1
|
||||
exit
|
||||
end if
|
||||
printf(1,", ")
|
||||
end for
|
||||
printf(1,"\n")
|
||||
if found then exit end if
|
||||
end for
|
||||
12
Task/Loops-Nested/Phix/loops-nested-2.phix
Normal file
12
Task/Loops-Nested/Phix/loops-nested-2.phix
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
procedure till20()
|
||||
for i=1 to 20 do
|
||||
for j=1 to 20 do
|
||||
printf(1,"%d",s[i][j])
|
||||
if s[i][j]=20 then return end if
|
||||
printf(1,", ")
|
||||
end for
|
||||
printf(1,"\n")
|
||||
end for
|
||||
end procedure
|
||||
till20()
|
||||
printf(1,"\n")
|
||||
10
Task/Loops-Nested/Phix/loops-nested-3.phix
Normal file
10
Task/Loops-Nested/Phix/loops-nested-3.phix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
for i=1 to 20 do
|
||||
for j=1 to 20 do
|
||||
printf(1,"%d",s[i][j])
|
||||
if s[i][j]=20 then #ilASM{jmp :%done} end if
|
||||
printf(1,", ")
|
||||
end for
|
||||
printf(1,"\n")
|
||||
end for
|
||||
#ilASM{:%done}
|
||||
printf(1,"\n")
|
||||
23
Task/Loops-Nested/Ring/loops-nested.ring
Normal file
23
Task/Loops-Nested/Ring/loops-nested.ring
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
size = 5
|
||||
array = newlist(size,size)
|
||||
for row = 1 to size
|
||||
for col = 1 to size
|
||||
array[row][col] = random(19) + 1
|
||||
next
|
||||
next
|
||||
|
||||
for row = 1 to size
|
||||
for col = 1 to size
|
||||
see "row " + row + " col " + col + "value : " + array[row][col] + nl
|
||||
if array[row][col] = 20 exit for row ok
|
||||
next
|
||||
next
|
||||
|
||||
func newlist x, y
|
||||
if isstring(x) x=0+x ok
|
||||
if isstring(y) y=0+y ok
|
||||
aList = list(x)
|
||||
for t in aList
|
||||
t = list(y)
|
||||
next
|
||||
return aList
|
||||
11
Task/Loops-Nested/Sidef/loops-nested.sidef
Normal file
11
Task/Loops-Nested/Sidef/loops-nested.sidef
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
var arr = 10.of{ 10.of{ 20.irand + 1 } }
|
||||
|
||||
for row in arr {
|
||||
for num in row {
|
||||
"%3d".printf(num);
|
||||
num == 20 && goto :OUT
|
||||
}
|
||||
print "\n"
|
||||
} @:OUT
|
||||
|
||||
print "\n"
|
||||
9
Task/Loops-Nested/Swift/loops-nested.swift
Normal file
9
Task/Loops-Nested/Swift/loops-nested.swift
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let array = [[2, 12, 10, 4], [18, 11, 20, 2]]
|
||||
|
||||
loop: for row in array {
|
||||
for element in row {
|
||||
println(" \(element)")
|
||||
if element == 20 { break loop }
|
||||
}
|
||||
}
|
||||
print("done")
|
||||
Loading…
Add table
Add a link
Reference in a new issue