Notifications
Clear all

[Closed] Maxscript challenge ideas

 lo1

it does not guarantee the numbers will be unique.

I better sit back and watch

 j83

Just a side note, don’t have a truly unique 1 to 1,000,000 random array just yet (have a repetitive one, but that’s not the point), but I just learned to never use makeUniqueArray with such a large array. >.<

hehehe

Oh, and “Linguistics” is currently winning while we’re working through this mini-challenge.

Maybe I’ll have something better to show this evening once I have time to think about it.

please don’t think the task is abstract.
for example: randomly pick some % of particles.

Picking up on what lo did:

(
	print "V1"
	start = timestamp()
	seed(timestamp())
	mem = heapfree
	results = #{1..1000000} as array
	for i = 1 to 1000000 do swap results[i] (results[random 1 1000000])
	end = timestamp()
	format "processing: % seconds heap: %
" ((end - start) / 1000.0) (heapfree-mem)
)
(
	print "V2"
	start = timestamp()
	seed(timestamp())
	mem = heapfree
	results=#()
	results[1000000] = 0
	for i = 1 to 1000000 do results[i] = i
	for i = 1 to 1000000 do swap results[i] (results[random 1 1000000])
	end = timestamp()
	format "processing: % seconds heap: %
" ((end - start) / 1000.0) (heapfree-mem)
)
(
	print "V3"
	start = timestamp()
	seed(timestamp())
	mem = heapfree
	results = for i = 1 to 1000000 collect i
	for i = 1 to 1000000 do swap results[i] (results[random 1 1000000])
	end = timestamp()
	format "processing: % seconds heap: %
" ((end - start) / 1000.0) (heapfree-mem)
)

Results:

"V1"
processing: 3.671 seconds heap: 45621096L
OK
"V2"
processing: 1.816 seconds heap: -17633800L
OK
"V3"
processing: 1.597 seconds heap: -27991360L
OK

Dunno about those memory results but hey…

 lo1

interesting that collect is the fastest method, I could swear I had opposite results this morning.

Your memory results, as mentioned earlier, are a result of not having enough free heap to do the whole loop so a GC is called midway.
Increase your heapsize to something ridiculous if you want accurate results.

One more:

(
	print "V4"
	start = timestamp()
	seed(timestamp())
	mem = heapfree
	results = for i = 1 to 1000000 collect i
	for i in results do swap i (results[random 1 1000000])
	end = timestamp()
	format "processing: % seconds heap: %
" ((end - start) / 1000.0) (mem-heapfree)
)

Results:

"V1"
processing: 3.697 seconds heap: -392029896L
OK
"V2"
processing: 1.501 seconds heap: 56000248L
OK
"V3"
processing: 1.348 seconds heap: 56000248L
OK
"V4"
processing: 1.145 seconds heap: 56000248L
1 Reply
 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

first 10 members of results array:
360541
436383
3
4
5
37200
7
17191
593939
10

it doesn’t work right.
also to get correct test you have to call GC before every test

1 Reply
(@kameleon)
Joined: 11 months ago

Posts: 0

Why isnt it working right? Kind of a mystery to me Works on some indexes and not on others

 lo1

swap requires two destinations, currently you are swapping a member of an array with a number literal, which doesn’t make sense, as the transfer can only go one way in that direction.

(
	print "V4"
	start = timestamp()
	seed(timestamp())
	mem = heapfree
	results = for i = 1 to 10 collect i
	for i in results do 
	(
		swap i results[random 1 10]
		print (results as string)
	)
	end = timestamp()
	format "processing: % seconds heap: %
" ((end - start) / 1000.0) (mem-heapfree)
)
"V4"
"#(1, 2, 3, 4, 5, 6, 7, 8, 1, 10)"
"#(1, 2, 2, 4, 5, 6, 7, 8, 1, 10)"
"#(2, 2, 2, 4, 5, 6, 7, 8, 1, 10)"
"#(2, 2, 2, 4, 5, 6, 7, 8, 4, 10)"
"#(2, 2, 2, 4, 5, 6, 7, 5, 4, 10)"
"#(6, 2, 2, 4, 5, 6, 7, 5, 4, 10)"
"#(6, 2, 2, 7, 5, 6, 7, 5, 4, 10)"
"#(6, 2, 5, 7, 5, 6, 7, 5, 4, 10)"
"#(6, 2, 5, 7, 4, 6, 7, 5, 4, 10)"
"#(6, 2, 5, 7, 4, 6, 7, 5, 4, 10)"

as you can see the values are not being swapped, only copied, resulting in duplicate values.

Got it, thanks!

btw, did another version only one character changed… lol it’s based on the V3

(
	print "V5"
	gc()
	start = timestamp()
	seed(timestamp())
	mem = heapfree
	results = for i = 1 to 1000000 collect i
	for i = 1 to 1000000 do swap results[i] (results[random i 1000000])
	end = timestamp()
	format "processing: % seconds heap: %
" ((end - start) / 1000.0) (mem-heapfree)
	for i = 1 to 10 do print results[i]
)

Now the results (with the gc() before each one)

"V1"
processing: 1.5 seconds heap: 224065624L
OK
"V2"
processing: 1.499 seconds heap: 56065344L
OK
"V3"
processing: 1.346 seconds heap: 56065344L
OK
"V5"
processing: 1.334 seconds heap: 56065344L
OK

The only thing I’ve changed is the random index generation, we dont need to go everytime from 1 to 1000000 because after each for loop the indexes < i are already randomized.

Page 4 / 12