Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1 +1,3 @@
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over <math>[1,\ldots,20]</math>. 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.
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over <math>[1,\ldots,20]</math>.
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.

View file

@ -0,0 +1,9 @@
<Cfset RandNum = 0>
<Cfloop condition="randNum neq 20">
<Cfloop from="1" to="5" index="i">
<Cfset randNum = RandRange(1, 20)>
<Cfoutput>#randNum# </Cfoutput>
<Cfif RandNum eq 20><cfbreak></Cfif>
</Cfloop>
<br>
</Cfloop>

View file

@ -0,0 +1,11 @@
fn scan_Nested arr =
(
for subArray in arr where classof subArray == Array do
(
for item in subArray do
(
print item as string
if item == 20 do return OK
)
)
)

View file

@ -0,0 +1,11 @@
testArray = #(#(1,5,2,19),#(11,20,7,2))
scan_nested testArray
#(#(1, 5, 2, 19), #(11, 20, 7, 2))
1
5
2
19
11
20
OK

View file

@ -0,0 +1,11 @@
(let (a (array 10 10))
(dotimes (i 10)
(dotimes (j 10)
(setf (a i j) (rand 21))))
(catch
(dotimes (i 10)
(dotimes (j 10)
(print (a i j))
(print " ")
(if (= 20 (a i j))
(throw))))))

View file

@ -0,0 +1,14 @@
numbers = .array~new()
do i = 1 to 10
do j = 1 to 10
numbers[i,j] = random(1, 20)
end
end
do i = 1 to numbers~dimension(1)
do j = 1 to numbers~dimension(2)
say numbers[i,j]
if numbers[i,j] = 20 then
leave i
end
end

View file

@ -1,18 +1,22 @@
/*REXX program to loop through a 2-dimensional array to look for a '20'.*/
rows=60
cols=10
do row =1 for rows /*1st dimension ∙∙∙ */
do col=1 for cols /*2nd dimension ∙∙∙ */
@.row.col=random(1,20) /*generate some nums.*/
/*REXX program loops through a 2-dimensional array to look for a '20'. */
parse arg rows cols targ . /*obtain optional args from C.L. */
if rows=='' | rows==',' then rows=60 /*Rows not specified? Use default*/
if cols=='' | cols==',' then cols=10 /*Cols " " " " */
if targ=='' | targ==',' then targ=20 /*Targ " " " " */
w=max(length(rows),length(cols),length(targ)) /*for formatting output.*/
not='not' /* [↓] construct the 2-dim array.*/
do row=1 for rows /*1st dimension of the array. */
do col=1 for cols /*2nd " " " " */
@.row.col=random(1,targ) /*generate some random numbers. */
end /*row*/
end /*col*/
/*─────────────────────────────────────now, search for the hidden twenty*/
do r =1 for rows
do c=1 for cols
say left('@.'r"."c,9) '=' right(@.r.c,4)
if @.r.c==20 then leave r
end /*c*/
end /*r*/
/*═════════════════════════════════════now, search for the target {20}.*/
do r=1 for rows
do c=1 for cols
say left('@.'r"."c,3+w+w) '=' right(@.r.c,w) /*display.*/
if @.r.c==targ then do; not=; leave r; end /*found ? */
end /*c*/
end /*r*/
say right(' Done with Loops/Nested. ',50,'')
say right(space('Target' not 'found:') targ, 33, '')
/*stick a fork in it, we're done.*/

View file

@ -1,4 +1,3 @@
srand
ary = (1..20).to_a.shuffle.each_slice(4).to_a
p ary

View file

@ -0,0 +1,8 @@
slices = (1..20).to_a.shuffle.each_slice(4)
slices.any? do |slice|
slice.any? do |element|
puts element
element == 20
end
end