Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Arrays/Groovy/arrays-1.groovy
Normal file
20
Task/Arrays/Groovy/arrays-1.groovy
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
def aa = [ 1, 25, 31, -3 ] // list
|
||||
def a = [0] * 100 // list of 100 zeroes
|
||||
def b = 1..9 // range notation
|
||||
def c = (1..10).collect { 2.0**it } // each output element is 2**(corresponding invoking list element)
|
||||
|
||||
// There are no true "multi-dimensional" arrays in Groovy (as in most C-derived languages).
|
||||
// Use lists of lists in natural ("row major") order as a stand in.
|
||||
def d = (0..1).collect { i -> (1..5).collect { j -> 2**(5*i+j) as double } }
|
||||
def e = [ [ 1.0, 2.0, 3.0, 4.0 ],
|
||||
[ 5.0, 6.0, 7.0, 8.0 ],
|
||||
[ 9.0, 10.0, 11.0, 12.0 ],
|
||||
[ 13.0, 14.0, 15.0, 16.0 ] ]
|
||||
|
||||
println aa
|
||||
println b
|
||||
println c
|
||||
println()
|
||||
d.each { print "["; it.each { elt -> printf "%7.1f ", elt }; println "]" }
|
||||
println()
|
||||
e.each { print "["; it.each { elt -> printf "%7.1f ", elt }; println "]" }
|
||||
3
Task/Arrays/Groovy/arrays-2.groovy
Normal file
3
Task/Arrays/Groovy/arrays-2.groovy
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def identity = { n ->
|
||||
(1..n).collect { i -> (1..n).collect { j -> i==j ? 1.0 : 0.0 } }
|
||||
}
|
||||
7
Task/Arrays/Groovy/arrays-3.groovy
Normal file
7
Task/Arrays/Groovy/arrays-3.groovy
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def i2 = identity(2)
|
||||
def i15 = identity(15)
|
||||
|
||||
|
||||
i2.each { print "["; it.each { elt -> printf "%4.1f ", elt }; println "]" }
|
||||
println()
|
||||
i15.each { print "["; it.each { elt -> printf "%4.1f ", elt }; println "]" }
|
||||
11
Task/Arrays/Groovy/arrays-4.groovy
Normal file
11
Task/Arrays/Groovy/arrays-4.groovy
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def strings = ['Mary', 'had', 'a', 'little', 'lamb', ". It's", 'fleece', 'was', 'white', 'as', 'snow']
|
||||
|
||||
println strings
|
||||
|
||||
strings[0] = 'Arthur'
|
||||
strings[4] = 'towel'
|
||||
strings[6] = 'stain'
|
||||
strings[8] = 'ripe'
|
||||
strings[10] = 'strawberries'
|
||||
|
||||
println strings
|
||||
1
Task/Arrays/Groovy/arrays-5.groovy
Normal file
1
Task/Arrays/Groovy/arrays-5.groovy
Normal file
|
|
@ -0,0 +1 @@
|
|||
println strings[-1]
|
||||
3
Task/Arrays/Groovy/arrays-6.groovy
Normal file
3
Task/Arrays/Groovy/arrays-6.groovy
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
println strings[0, 7, 2, 3, 8]
|
||||
println strings[0..4]
|
||||
println strings[0..3, -5]
|
||||
Loading…
Add table
Add a link
Reference in a new issue