June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -3,4 +3,20 @@ Show a nested loop which searches a two-dimensional array filled with random num
The loops iterate rows and columns of the array printing the elements until the value <math>20</math> is met.
Specifically, this task also shows how to [[Loop/Break|break]] out of nested loops.
;Related tasks:
* &nbsp; [[Loop over multiple arrays simultaneously]]
* &nbsp; [[Loops/Break]]
* &nbsp; [[Loops/Continue]]
* &nbsp; [[Loops/Do-while]]
* &nbsp; [[Loops/Downward for]]
* &nbsp; [[Loops/For]]
* &nbsp; [[Loops/For with a specified step]]
* &nbsp; [[Loops/Foreach]]
* &nbsp; [[Loops/Increment loop index within loop body]]
* &nbsp; [[Loops/Infinite]]
* &nbsp; [[Loops/N plus one half]]
* &nbsp; [[Loops/Nested]]
* &nbsp; [[Loops/While]]
<br><br>

View file

@ -0,0 +1,22 @@
'BEGIN' 'COMMENT' Loops/Nested - ALGOL60 - 19/06/2018;
'INTEGER' SEED;
'INTEGER' 'PROCEDURE' RANDOM(N);
'VALUE' N; 'INTEGER' N;
'BEGIN'
SEED:=(SEED*19157+12347) '/' 21647;
RANDOM:=SEED-(SEED '/' N)*N+1
'END' RANDOM;
'INTEGER' 'ARRAY' A(/1:10,1:10/);
'INTEGER' I,J;
SEED:=31569;
'FOR' I:=1 'STEP' 1 'UNTIL' 10 'DO'
'FOR' J:=1 'STEP' 1 'UNTIL' 10 'DO'
A(/I,J/):=RANDOM(20);
SYSACT(1,6,120);SYSACT(1,8,60);SYSACT(1,12,1);'COMMENT' open print;
'FOR' I:=1 'STEP' 1 'UNTIL' 10 'DO'
'FOR' J:=1 'STEP' 1 'UNTIL' 10 'DO' 'BEGIN'
OUTINTEGER(1,A(/I,J/));
'IF' A(/I,J/)=20 'THEN' 'GOTO' LAB;
'END';
LAB:
'END'

View file

@ -0,0 +1,10 @@
USING: continuations formatting io kernel math.ranges
prettyprint random sequences ;
IN: rosetta-code.loops-nested
: rand-table ( -- seq )
10 [ 20 [ 20 [1,b] random ] replicate ] replicate ;
rand-table [
[ [ dup "%4d" printf 20 = [ return ] when ] each nl ] each
] with-return drop

View file

@ -1,5 +1,5 @@
import Data.List
breakIncl :: (a -> Bool) -> [a] -> [a]
breakIncl p = uncurry ((. take 1). (++)). break p
taskLLB k = map (breakIncl (==k)). breakIncl (k`elem`)
taskLLB k = map (breakIncl (==k)). breakIncl (k `elem`)

View file

@ -1,8 +1,4 @@
mij :: [[Int]]
mij = takeWhile(not.null). unfoldr (Just. splitAt 5) $
[2, 6, 17, 5, 14, 1, 9, 11, 18, 10, 13, 20, 8, 7, 4, 16, 15, 19, 3, 12]
*Main> mapM_ (mapM_ print) $ taskLLB 20 mij
*Main> mapM_ (mapM_ print) $ taskLLB 20 [[2,6,17,5,14],[1,9,11,18,10],[13,20,8,7,4],[16,15,19,3,12]]
2
6
17