Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View 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

View 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

View file

@ -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

View 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')
);

View 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

View 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

View 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.

View 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";

View file

@ -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!("");
}

View 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

View 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