Integer puzzle (with answer)
|
|
Bjørn
|
Tue Aug 11 2009, 06:48AM
|
|
|
Registered Member #27
Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
|
This code will generate some of the possible combinations of x and y but it will repeat some combinations. How to generate the same combinations in the same order but skip the duplicates.
s = 256
Do
s = s / 2
For y = 0 To 255 - s Step s * 2
For x = 0 To 255 - s Step s * 2
Print x,y
Next x
Next y
Loop Until s = 1
|
Back to top
|
|
Bjørn
|
|
Registered Member #27
Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
|
The solution turned out to be simple and the first value turned out to be a special case. For some reason most people found this problem to be confusing and difficult to visualise.
s = 256
Do
s = s / 2
For y = 0 To 255 - s Step s * 2
For x = 0 To 255 - s Step s * 2
If (x And s*2) Or (y And s*2) Or (s = 128) Then Print x,y
Next x
Next y
Loop Until s = 1 When doing in place wavelet transform of a picture, this is the order the transformed values have to be saved to a file or transmitted to make sure the image gradually increases in resolution as more values becomes available,
|
Back to top
|
|
Moderator(s): Chris Russell, Noelle, Alex, Tesladownunder, Dave Marshall, Dave Billington, Bjørn, Steve Conner, Wolfram, Kizmo, Mads Barnkob
|
|
Powered by e107 Forum System
|