Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
4
Task/Loops-Nested/Factor/loops-nested-1.factor
Normal file
4
Task/Loops-Nested/Factor/loops-nested-1.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
USING: io kernel math.ranges prettyprint random sequences ;
|
||||
|
||||
10 [ 20 [ 20 [1,b] random ] replicate ] replicate ! make a table of random values
|
||||
[ [ dup pprint bl 20 = ] find nl drop ] find 2drop ! print values until 20 is found
|
||||
7
Task/Loops-Nested/Factor/loops-nested-2.factor
Normal file
7
Task/Loops-Nested/Factor/loops-nested-2.factor
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
USING: continuations io kernel math.ranges prettyprint random
|
||||
sequences ;
|
||||
|
||||
10 [ 20 [ 20 [1,b] random ] replicate ] replicate ! make a table of random values
|
||||
[
|
||||
[ [ dup pprint bl 20 = [ return ] when ] each nl ] each ! print values until 20 is found
|
||||
] with-return drop
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
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
|
||||
24
Task/Loops-Nested/Pike/loops-nested.pike
Normal file
24
Task/Loops-Nested/Pike/loops-nested.pike
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
int main()
|
||||
{
|
||||
// enumerate() normally returns a linearly enumerated array, but
|
||||
// allows for the forth argument to specify a function that will
|
||||
// be called and return the value that should be in each cell. We
|
||||
// create an anonymous function (lambda) that just returns a
|
||||
// random value.
|
||||
array a = ({});
|
||||
for(int i=0; i<20; i++)
|
||||
a += ({ enumerate( 20, 1, 1, lambda(){return random(20)+1;} ) });
|
||||
|
||||
// We could use for() and a[x][y] indexing, but foreach is just
|
||||
// shorter and easier to use even if the 2D-array becomes less
|
||||
// obvious.
|
||||
mynestedloops:
|
||||
foreach(a, array inner_a) {
|
||||
foreach(inner_a, int value) {
|
||||
write(value +" ");
|
||||
if(value == 20)
|
||||
break mynestedloops;
|
||||
}
|
||||
}
|
||||
write("\n");
|
||||
}
|
||||
20
Task/Loops-Nested/Vala/loops-nested.vala
Normal file
20
Task/Loops-Nested/Vala/loops-nested.vala
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
void main() {
|
||||
|
||||
int[,] a = new int[10, 10];
|
||||
bool broken = false;
|
||||
for (int i = 0; i < 10; i++)
|
||||
for (int j = 0; j < 10; j++)
|
||||
a[i, j] = Random.int_range(0, 21) % 20 + 1;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
stdout.printf(" %d", a[i, j]);
|
||||
if (a[i, j] == 20) {
|
||||
broken = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
stdout.printf("\n");
|
||||
if (broken) break;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue