Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -7,3 +7,6 @@ For this task, show how two loops may be nested within each other, with the numb
|
|||
***
|
||||
****
|
||||
*****</pre>
|
||||
|
||||
;Reference:
|
||||
* [[wp:For loop|For loop]] Wikipedia.
|
||||
|
|
|
|||
23
Task/Loops-For/360-Assembly/loops-for.360
Normal file
23
Task/Loops-For/360-Assembly/loops-for.360
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
LOOPFORC CSECT
|
||||
USING LOOPFORC,R12
|
||||
LR R12,R15 set base register
|
||||
BEGIN SR R2,R2 from 1
|
||||
LA R4,1 by 1
|
||||
LA R5,5 to 5
|
||||
LOOPI BXH R2,R4,ELOOPI i (R2)
|
||||
LA R8,BUFFER-1
|
||||
SR R3,R3 from 1
|
||||
LA R6,1 by 1
|
||||
LR R7,R2 to i
|
||||
LOOPJ BXH R3,R6,ELOOPJ j (R3)
|
||||
LA R8,1(R8)
|
||||
MVI 0(R8),C'*'
|
||||
B LOOPJ
|
||||
ELOOPJ XPRNT BUFFER,L'BUFFER
|
||||
B LOOPI
|
||||
ELOOPI EQU *
|
||||
RETURN XR R15,R15 set return code
|
||||
BR R14 return to caller
|
||||
BUFFER DC CL80' '
|
||||
YREGS
|
||||
END LOOPFORC
|
||||
10
Task/Loops-For/ALGOL-W/loops-for.alg
Normal file
10
Task/Loops-For/ALGOL-W/loops-for.alg
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
begin
|
||||
for i := 1 until 5 do
|
||||
begin
|
||||
write( "*" );
|
||||
for j := 2 until i do
|
||||
begin
|
||||
writeon( "*" )
|
||||
end j
|
||||
end i
|
||||
end.
|
||||
13
Task/Loops-For/Ela/loops-for-1.ela
Normal file
13
Task/Loops-For/Ela/loops-for-1.ela
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
open monad io
|
||||
|
||||
loop m n | n < m = do
|
||||
loop' n 0
|
||||
putStrLn ""
|
||||
loop m (n + 1)
|
||||
| else = do return ()
|
||||
where loop' m n | n <= m = do
|
||||
putStr "*"
|
||||
loop' m (n + 1)
|
||||
| else = do return ()
|
||||
|
||||
_ = loop 10 1 ::: IO
|
||||
9
Task/Loops-For/Ela/loops-for-2.ela
Normal file
9
Task/Loops-For/Ela/loops-for-2.ela
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
**
|
||||
***
|
||||
****
|
||||
*****
|
||||
******
|
||||
*******
|
||||
********
|
||||
*********
|
||||
**********
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
open console
|
||||
|
||||
loop m n | n < m = loop' n 0 $ writen "" $ loop m (n+1)
|
||||
| else = ()
|
||||
where loop' m n | n <= m = write "*" $ loop' m (n+1)
|
||||
| else = ()
|
||||
10
Task/Loops-For/Elixir/loops-for.elixir
Normal file
10
Task/Loops-For/Elixir/loops-for.elixir
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
defmodule Loops do
|
||||
def loops_for(n) do
|
||||
Enum.each(1..n, fn i ->
|
||||
Enum.each(1..i, fn _ -> IO.write "*" end)
|
||||
IO.puts ""
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
Loops.loops_for(5)
|
||||
3
Task/Loops-For/Fortran/loops-for-4.f
Normal file
3
Task/Loops-For/Fortran/loops-for-4.f
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
DO 1 I = 1,5
|
||||
1 WRITE (6,*) ("*", J = 1,I)
|
||||
END
|
||||
4
Task/Loops-For/Fortran/loops-for-5.f
Normal file
4
Task/Loops-For/Fortran/loops-for-5.f
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
DO 1 I = 1,5
|
||||
1 WRITE (6,2) (666, J = 1,I)
|
||||
2 FORMAT(5I1)
|
||||
END
|
||||
5
Task/Loops-For/JavaScript/loops-for-2.js
Normal file
5
Task/Loops-For/JavaScript/loops-for-2.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
function range(i) {
|
||||
return i ? range(i - 1).concat(i) : [];
|
||||
}
|
||||
|
||||
range(5) --> [1, 2, 3, 4, 5]
|
||||
12
Task/Loops-For/JavaScript/loops-for-3.js
Normal file
12
Task/Loops-For/JavaScript/loops-for-3.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
var s = '';
|
||||
|
||||
range(5).forEach(
|
||||
function (line) {
|
||||
range(line).forEach(
|
||||
function () { s += '*'; }
|
||||
);
|
||||
s += '\n';
|
||||
}
|
||||
);
|
||||
|
||||
console.log(s);
|
||||
7
Task/Loops-For/JavaScript/loops-for-4.js
Normal file
7
Task/Loops-For/JavaScript/loops-for-4.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
console.log(
|
||||
range(5).reduce(
|
||||
function (a, n) {
|
||||
return a + Array(n + 1).join('*') + '\n';
|
||||
}, ''
|
||||
)
|
||||
);
|
||||
5
Task/Loops-For/JavaScript/loops-for-5.js
Normal file
5
Task/Loops-For/JavaScript/loops-for-5.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
console.log(
|
||||
range(5).map(function(a) {
|
||||
return Array(a + 1).join('*');
|
||||
}).join('\n')
|
||||
);
|
||||
6
Task/Loops-For/Julia/loops-for.julia
Normal file
6
Task/Loops-For/Julia/loops-for.julia
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
for i in 1:5
|
||||
for j in 1:i
|
||||
print("*")
|
||||
end
|
||||
println()
|
||||
end
|
||||
7
Task/Loops-For/Rust/loops-for.rust
Normal file
7
Task/Loops-For/Rust/loops-for.rust
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
for i in 0..5 {
|
||||
for _ in 0..(i + 1) {
|
||||
print!("*");
|
||||
}
|
||||
|
||||
print!("\n");
|
||||
}
|
||||
7
Task/Loops-For/Scilab/loops-for.scilab
Normal file
7
Task/Loops-For/Scilab/loops-for.scilab
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
for i=1:5
|
||||
s=""
|
||||
for j=1:i
|
||||
s=s+"*"
|
||||
end
|
||||
printf("%s\n",s)
|
||||
end
|
||||
41
Task/Loops-For/Z80-Assembly/loops-for.z80
Normal file
41
Task/Loops-For/Z80-Assembly/loops-for.z80
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
org &4000 ; put code at memory address 0x4000
|
||||
wr_char equ &bb5a ; write ASCII character in register A to screen
|
||||
; (jumps into CPC ROM)
|
||||
|
||||
; put registers on stack so we can return to BASIC later
|
||||
push bc
|
||||
push de
|
||||
push hl
|
||||
|
||||
ld b,5 ; loop from 5 to 1
|
||||
|
||||
row:
|
||||
|
||||
push bc ; save outer loop variable
|
||||
|
||||
; calculate inner loop limit (6 - outer loop variable)
|
||||
ld a,6
|
||||
sub b
|
||||
ld b,a
|
||||
|
||||
column:
|
||||
|
||||
ld a,42 ; asterisk in ASCII
|
||||
call wr_char
|
||||
djnz column ; decrement B, jump to label if non-zero
|
||||
|
||||
pop bc ; restore outer loop
|
||||
|
||||
; print carriage return/line feed
|
||||
ld a,13
|
||||
call wr_char
|
||||
ld a,10
|
||||
call wr_char
|
||||
|
||||
djnz row
|
||||
|
||||
; restore registers
|
||||
pop hl
|
||||
pop de
|
||||
pop bc
|
||||
ret ; return to BASIC interpreter
|
||||
Loading…
Add table
Add a link
Reference in a new issue