Notifications
Clear all

[Closed] Last bit?

More elegant

fn lastbit1 bits = amax (bits as array)
fn lastbit7 bits = 
(
	pivot = 1
	while (p = (pivot + bits.count)/2) > pivot do
	(
		bb = #{p+1..bits.count} * bits
		if not bb.isEmpty then 
		(
			bits = bb
			pivot = p
		)
		else 
		(
			bits = #{pivot..p} * bits
		)
	)
	(bits as array)[1]
)

here is a binary cut without recursion and .numberset

and it’s 20% faster also

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

but anyway it’s using your idea you are the winner currently

something is missed in my last method… it’s loosing some performance with no sense. i don’t have time right now to fix it. maybe later…

the only one comment… maximum float ‘integer’ is 16777216 so your method implementation is limited by this count

c’mon, it slows down the algorithm

Well, elegance has its price ;).

Replace (bits as array)[1] by bits.count and you get another 20% improvement ;)… And a little less memory ussage too.

3 Replies
(@denist)
Joined: 11 months ago

Posts: 0

absolutely!

(@aaandres)
Joined: 11 months ago

Posts: 0

Or by pivot+1

(@denist)
Joined: 11 months ago

Posts: 0

hah! :keenly:

fn lastbit7 bits = 
(
	pivot = 1
	while (p = (pivot + bits.count)/2) > pivot do
	(
		bb = #{p+1..bits.count} * bits
		if bb.isEmpty then 
		(
			bits = #{pivot..p} * bits
		)
		else 
		(
			bits = bb
			pivot = p
		)
	)
	bits.count
)


also i removed not before empty check

fn lastbit7 bits = 
(
	pivot = 1
	while (p = (pivot + bits.count)/2) > pivot do
	(
		bb = #{p+1..bits.count} * bits
		if bb.isEmpty then [B]bits.count = p[/B]
		else 
		(
			bits = bb
			pivot = p
		)
	)
	p+1
)


the only thing i still don’t like is

bb = #{p+1..bits.count} * bits

Page 2 / 4