combinatorics example

main
villares 2019-05-18 12:27:46 -03:00
rodzic 1d4d91017a
commit 66d494cc85
2 zmienionych plików z 32 dodań i 0 usunięć

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 24 KiB

Wyświetl plik

@ -0,0 +1,32 @@
"""*
* A simple example for class Combination.
* fjenett 20090306
"""
add_library('Combinatorics')
def setup():
size(500, 500)
background(0)
fill(255, 0, 0)
textSize(11)
chars = "0123456789ABCDEF"
# Generate the following combinations:
# place 16 elements on 3 positions
combinations = Combination(len(chars), 3)
println(combinations.totalAsInt())
h = height / (combinations.totalAsInt() + 0.5) * 10.8
x, y, w = 0, h, 48
while (combinations.hasMore()):
c = combinations.next()
t = chars[c[0]] + " " + chars[c[1]] + " " + chars[c[2]]
text(t, 20 + x, 5 + y)
x += w
if x > width:
x = 0
y += h
saveFrame("sketch_190518a.png")
noLoop()