Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
74
Task/Loops-Nested/360-Assembly/loops-nested.360
Normal file
74
Task/Loops-Nested/360-Assembly/loops-nested.360
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
* Loop nested 12/08/2015
|
||||
LOOPNEST CSECT
|
||||
USING LOOPNEST,R12
|
||||
LR R12,R15
|
||||
BEGIN LA R6,0 i
|
||||
LA R8,1
|
||||
LA R9,20
|
||||
LOOPI1 BXH R6,R8,ELOOPI1 do i=1 to hbound(x,1)
|
||||
LA R7,0 j
|
||||
LA R10,1
|
||||
LA R11,20
|
||||
LOOPJ1 BXH R7,R10,ELOOPJ1 do j=1 to hbound(x,2)
|
||||
L R5,RANDSEED n
|
||||
M R4,=F'397204094' r4r5=n*const
|
||||
D R4,=X'7FFFFFFF' r5=r5 div (2^31-1)
|
||||
ST R4,RANDSEED r4=r5 mod (2^31-1) ; n=r4
|
||||
LR R5,R4 r5=n
|
||||
LA R4,0
|
||||
D R4,=F'20' r5=n div nn; r4=n mod nn
|
||||
LR R2,R4 r2=randint(nn) [0:nn-1]
|
||||
LA R2,1(R2) randint(nn)+1
|
||||
LR R1,R6 i
|
||||
BCTR R1,0
|
||||
MH R1,=H'20'
|
||||
LR R5,R7 j
|
||||
BCTR R5,0
|
||||
AR R1,R5
|
||||
SLA R1,2
|
||||
ST R2,X(R1) x(i,j)=randint(20)+1
|
||||
B LOOPJ1
|
||||
ELOOPJ1 B LOOPI1
|
||||
ELOOPI1 MVC MVCZ,=CL80' '
|
||||
LA R6,0 i
|
||||
LA R8,1
|
||||
LA R9,20
|
||||
LOOPI2 BXH R6,R8,ELOOPI2 do i=1 to hbound(x,1)
|
||||
LA R7,0 j
|
||||
LA R10,1
|
||||
LA R11,20
|
||||
LOOPJ2 BXH R7,R10,ELOOPJ2 do j=1 to hbound(x,2)
|
||||
LR R1,R6
|
||||
BCTR R1,0
|
||||
MH R1,=H'20'
|
||||
LR R5,R7
|
||||
BCTR R5,0
|
||||
AR R1,R5
|
||||
SLA R1,2
|
||||
L R5,X(R1) x(i,j)
|
||||
LR R2,R5
|
||||
LA R3,MVCZ
|
||||
AH R3,MVCI
|
||||
XDECO R2,XDEC
|
||||
MVC 0(4,R3),XDEC+8
|
||||
LH R3,MVCI
|
||||
LA R3,4(R3)
|
||||
STH R3,MVCI
|
||||
L R5,X(R1)
|
||||
C R5,=F'20' if x(i,j)=20
|
||||
BE ELOOPI2 then exit
|
||||
B LOOPJ2
|
||||
ELOOPJ2 XPRNT MVCZ,80
|
||||
MVC MVCI,=H'0'
|
||||
MVC MVCZ,=CL80' '
|
||||
B LOOPI2
|
||||
ELOOPI2 XPRNT MVCZ,80
|
||||
RETURN XR R15,R15
|
||||
BR R14
|
||||
X DS 400F
|
||||
MVCZ DS CL80
|
||||
MVCI DC H'0'
|
||||
XDEC DS CL16
|
||||
RANDSEED DC F'16807' running n
|
||||
YREGS
|
||||
END LOOPNEST
|
||||
24
Task/Loops-Nested/Elixir/loops-nested.elixir
Normal file
24
Task/Loops-Nested/Elixir/loops-nested.elixir
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
defmodule Loops do
|
||||
def nested do
|
||||
:random.seed(:os.timestamp)
|
||||
list = Enum.shuffle(1..20) |> Enum.chunk(5)
|
||||
IO.inspect list, char_lists: :as_lists
|
||||
try do
|
||||
nested(list)
|
||||
catch
|
||||
:find -> IO.puts "done"
|
||||
end
|
||||
end
|
||||
|
||||
def nested(list) do
|
||||
Enum.each(list, fn row ->
|
||||
Enum.each(row, fn x ->
|
||||
IO.write "#{x} "
|
||||
if x == 20, do: throw(:find)
|
||||
end)
|
||||
IO.puts ""
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
Loops.nested
|
||||
|
|
@ -35,10 +35,10 @@ C makes everybody so comfortable.
|
|||
5000 FORMAT('A[', I2, '][', I2, '] is ', I2)
|
||||
END
|
||||
|
||||
C FORTRAN 77 does not have come with a random number generator, but it
|
||||
C is easy enough to type "fortran 77 random number generator" into your
|
||||
C preferred search engine and to copy and paste what you find. The
|
||||
C following code is a slightly-modified version of:
|
||||
C FORTRAN 77 does not come with a random number generator, but it is
|
||||
C easy enough to type "fortran 77 random number generator" into your
|
||||
C preferred search engine and to copy and paste what you find.
|
||||
C The following code is a slightly-modified version of:
|
||||
C
|
||||
C http://www.tat.physik.uni-tuebingen.de/
|
||||
C ~kley/lehre/ftn77/tutorial/subprograms.html
|
||||
|
|
|
|||
43
Task/Loops-Nested/JavaScript/loops-nested-2.js
Normal file
43
Task/Loops-Nested/JavaScript/loops-nested-2.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
var lst = [[2, 12, 10, 4], [18, 11, 9, 3], [14, 15, 7, 17], [6, 19, 8, 13], [1,
|
||||
20, 16, 5]];
|
||||
|
||||
var takeWhile = function (lst, fnTest) {
|
||||
'use strict';
|
||||
var varHead = lst.length ? lst[0] : null;
|
||||
|
||||
return varHead ? (
|
||||
fnTest(varHead) ? [varHead].concat(
|
||||
takeWhile(lst.slice(1), fnTest)
|
||||
) : []
|
||||
) : []
|
||||
},
|
||||
|
||||
// The takeWhile function terminates when notTwenty(n) returns false
|
||||
notTwenty = function (n) {
|
||||
return n !== 20;
|
||||
},
|
||||
|
||||
// Leftward groups containing no 20
|
||||
// takeWhile nested within takeWhile
|
||||
lstChecked = takeWhile(lst, function (group) {
|
||||
return takeWhile(
|
||||
group,
|
||||
notTwenty
|
||||
).length === 4;
|
||||
});
|
||||
|
||||
|
||||
// Return the trail of numbers preceding 20 from a composable expression
|
||||
|
||||
console.log(
|
||||
// Numbers before 20 in a group in which it was found
|
||||
lstChecked.concat(
|
||||
takeWhile(
|
||||
lst[lstChecked.length], notTwenty
|
||||
)
|
||||
)
|
||||
// flattened
|
||||
.reduce(function (a, x) {
|
||||
return a.concat(x);
|
||||
}).join('\n')
|
||||
);
|
||||
21
Task/Loops-Nested/JavaScript/loops-nested-3.js
Normal file
21
Task/Loops-Nested/JavaScript/loops-nested-3.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
2
|
||||
12
|
||||
10
|
||||
4
|
||||
18
|
||||
11
|
||||
9
|
||||
3
|
||||
14
|
||||
15
|
||||
7
|
||||
17
|
||||
6
|
||||
19
|
||||
8
|
||||
13
|
||||
6
|
||||
19
|
||||
8
|
||||
13
|
||||
1
|
||||
17
Task/Loops-Nested/Julia/loops-nested.julia
Normal file
17
Task/Loops-Nested/Julia/loops-nested.julia
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
M = [rand(1:20) for i in 1:5, j in 1:10]
|
||||
R, C = size(M)
|
||||
|
||||
println("The full matrix is:")
|
||||
println(M, "\n")
|
||||
|
||||
println("Find the first 20:")
|
||||
for i in 1:R, j in 1:C
|
||||
n = M[i,j]
|
||||
@printf "%4d" n
|
||||
if n == 20
|
||||
println()
|
||||
break
|
||||
elseif j == C
|
||||
println()
|
||||
end
|
||||
end
|
||||
21
Task/Loops-Nested/Pascal/loops-nested.pascal
Normal file
21
Task/Loops-Nested/Pascal/loops-nested.pascal
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
program LoopNested;
|
||||
uses SysUtils;
|
||||
const Ni=10; Nj=20;
|
||||
var
|
||||
tab: array[1..Ni,1..Nj] of Integer;
|
||||
i, j: Integer;
|
||||
label loopend;
|
||||
begin
|
||||
for i := 1 to Ni do
|
||||
for j := 1 to Nj do
|
||||
tab[i,j]:=random(20)+1;
|
||||
for i := 1 to Ni do
|
||||
begin
|
||||
for j := 1 to Nj do
|
||||
begin
|
||||
WriteLn(tab[i,j]);
|
||||
if tab[i,j]=20 then goto loopend
|
||||
end
|
||||
end;
|
||||
loopend:
|
||||
end.
|
||||
10
Task/Loops-Nested/Perl-6/loops-nested.pl6
Normal file
10
Task/Loops-Nested/Perl-6/loops-nested.pl6
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
my @a = [ (1..20).roll(10) ] xx *;
|
||||
|
||||
LINE: for @a -> @line {
|
||||
for @line -> $elem {
|
||||
print " $elem";
|
||||
last LINE if $elem == 20;
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
print "\n";
|
||||
|
|
@ -1,22 +1,21 @@
|
|||
// rust 0.9-pre
|
||||
use rand::Rng;
|
||||
|
||||
use std::rand::Rng;
|
||||
extern crate rand;
|
||||
|
||||
fn main() {
|
||||
let mut matrix = [[0u8, .. 10], .. 10];
|
||||
let mut rng = std::rand::os::OSRng::new();
|
||||
let mut matrix = [[0u8; 10]; 10];
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
for row in matrix.mut_iter() {
|
||||
for item in row.mut_iter() {
|
||||
*item = rng.gen_range(0u8, 21);
|
||||
for row in matrix.iter_mut() {
|
||||
for item in row.iter_mut() {
|
||||
*item = rng.gen_range(0, 21);
|
||||
}
|
||||
}
|
||||
|
||||
'outer:
|
||||
for row in matrix.iter() {
|
||||
'outer: for row in matrix.iter() {
|
||||
for &item in row.iter() {
|
||||
print!("{:2} ", item);
|
||||
if item == 20 { break 'outer; }
|
||||
if item == 20 { break 'outer }
|
||||
}
|
||||
println!("");
|
||||
}
|
||||
|
|
|
|||
10
Task/Loops-Nested/Scilab/loops-nested.scilab
Normal file
10
Task/Loops-Nested/Scilab/loops-nested.scilab
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
ni=3;nj=4
|
||||
t=int(rand(ni,nj)*20)+1
|
||||
for i=1:ni
|
||||
for j=1:nj
|
||||
printf("%2d ",t(i,j))
|
||||
if t(i,j)==11 then break; end
|
||||
end
|
||||
printf("\n")
|
||||
if t(i,j)==11 then break; end
|
||||
end
|
||||
18
Task/Loops-Nested/TI-83-BASIC/loops-nested.ti-83
Normal file
18
Task/Loops-Nested/TI-83-BASIC/loops-nested.ti-83
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
PROGRAM:LOOP
|
||||
(A,B)→dim([C])
|
||||
For(I,1,A)
|
||||
For(J,1,B)
|
||||
int(rand*20+1)→[C](I,J)
|
||||
End
|
||||
End
|
||||
For(I,1,A)
|
||||
For(J,1,B)
|
||||
Disp [C](I,J)
|
||||
If [C](I,J)=20
|
||||
Then
|
||||
Stop
|
||||
End
|
||||
End
|
||||
End
|
||||
|
||||
3→A:4→B:prgmLOOP
|
||||
Loading…
Add table
Add a link
Reference in a new issue