Right this will fox...
 

  You don't need to be an 'investor' to invest in Singletrack: 6 days left: 95% of target - Find out more

Right this will fox you (excel or other solution)

20 Posts
12 Users
2 Reactions
65 Views
Posts: 12507
Free Member
Topic starter
 

Number generator...

I need* to generate three columns of numbers which can contain 0 to 255. The columns are important so 0,0,255 is not the same as 0,255,0 or 255,0,0

I need to generate all combinations that are close say within +- of the middle value.

Any ideas?

* Need is strong word, but it is an interesting puzzle.


 
Posted : 14/03/2023 11:48 am
Posts: 3562
Full Member
 

Power Query in Excel sounds like what you want.


 
Posted : 14/03/2023 11:57 am
Posts: 9539
Free Member
 

Edited because I was talking bollocks 🙂


 
Posted : 14/03/2023 12:02 pm
Posts: 12865
Free Member
 

I typed the following prompt into ChatGPT, it spat out some text which I saved & then imported into Excel as a CSV:
"generate a 20 row, 3 column CSV file. The second column should be a random number between 0 and 255. the first and third columns should also be random numbers but each value should not be different by more than 10 from the value of the second column on the same row."

is that what you want? Must admit not really sure how to interpret this:

I need to generate all combinations that are close say within +- of the middle value.


 
Posted : 14/03/2023 12:10 pm
Posts: 50
Free Member
 

Use RandBetween function? Middle Column (B) would be between 0 and 255. First and Last col (A and C) would be between B-tolerance and b + tolerance.

So if your tolerance was say 20... and the middle random value came out at 100, Col A and Col C would be RandBetween 80 and 120.


 
Posted : 14/03/2023 12:22 pm
Posts: 12507
Free Member
Topic starter
 

is that what you want? Must admit not really sure how to interpret this:

I need to generate all combinations that are close say within +- of the middle value.

Yeah that's fair. +-10 of the middle value not middle column.

As in 8 from 8,6,250


 
Posted : 14/03/2023 12:39 pm
Posts: 12507
Free Member
Topic starter
 

Use RandBetween function? Middle Column (B) would be between 0 and 255. First and Last col (A and C) would be between B-tolerance and b + tolerance.

So if your tolerance was say 20… and the middle random value came out at 100, Col A and Col C would be RandBetween 80 and 120.

It can't be random it needs to be the complete list of combinations. 255is the max value in any cell.


 
Posted : 14/03/2023 12:43 pm
 Chew
Posts: 1312
Free Member
 

There are 266^3 combinations.....
Best part of 19 million


 
Posted : 14/03/2023 12:45 pm
Posts: 12507
Free Member
Topic starter
 

There are 266^3 combinations…..
Best part of 19 million

There aren't though.

Because most combinations would pass the condition.

Eh

1,11->255,0->255 all pass (or fail, depending on how you look at it)


 
Posted : 14/03/2023 12:47 pm
 poly
Posts: 8699
Free Member
 

josh:

this is by no means optimised but is hopefully fairly readable python code:

[code]

limit = 10 ## CHANGE THIS VALUE

all_values = []
output_values = []

for a in range(255):
....for b in range (255):
........for c in range (255):
............all_values.append((a,b,c))

for value in all_values:
....if abs(value[0]-value[1])<=limit and abs(value[2]-value[1])<=limit:
........output_values.append(value)

print(output_values)

[/code]

You may want to import the CSV module and save the output to csv to make it easier to play with.

AHHHHH - annoyingly the code tags on this site don't respect spaces!  So i had to put . in - swap all the leading dots for spaces


 
Posted : 14/03/2023 12:48 pm
Posts: 12507
Free Member
Topic starter
 

Cheers poly, I though python would be the answer.

Anyone want to guess what I am doing?


 
Posted : 14/03/2023 12:53 pm
 poly
Posts: 8699
Free Member
 

I hope you are not trying to look for similar colours!  If you were then probably switching from RGB to a different colour space like HSV would be better!

If its not a one-off you probably want to optimise that so you only generate the number if its in the desired range rather than generate them all and filtering out.  I don't know how much python you've done...


 
Posted : 14/03/2023 1:04 pm
Posts: 3445
Free Member
 

C#, loops, and write to CSV. Not too onerous at all.


 
Posted : 14/03/2023 1:08 pm
Posts: 12507
Free Member
Topic starter
 

I hope you are not trying to look for similar colours! If you were then probably switching from RGB to a different colour space like HSV would be better!

I am as it goes, trying to make a background map in some typically shonky utilities maps disappear in QGIS. I don't need to process them just make it easier to see through them. To be honest the 255 identical bands does remove most stuff this is more thought excercise and a reminder I need python skills beyond print("hello world") despite doing fancy edge detection stuff for my dissertation I've never got beyond stealing bits of code and piecing them together.

So anything from white to black and anything greyish.

If its not a one-off you probably want to optimise that so you only generate the number if its in the desired range rather than generate them all and filtering out. I don’t know how much python you’ve done…

Sounds like a first challenge.


 
Posted : 14/03/2023 1:21 pm
Posts: 4985
Free Member
 

I’ve never got beyond stealing bits of code and piecing them together.

Are you ALL the devs in my team?


 
Posted : 14/03/2023 1:39 pm
towpathman and leffeboy reacted
 toby
Posts: 532
Full Member
 

OK, this was my attempt in a generic mish-mash of languages:

for (middle = 0 ; middle <= 255 ; middle++) {
_ for (first = max(0, middle - 10) ; first <= min (middle + 10, 255) ; first++) {
_ _ for (last = max(0, middle - 10) ; last <= min (middle + 10, 255) ; last++) {
_ _ _ print first . ", " . middle . ", " . last . "\r\n";
_ _ }
_ }
}

Then I re-read the question and realised I don't understand something...

Yeah that’s fair. +-10 of the middle value not middle column.

As in 8 from 8,6,250

Within 10 what? 250 isn't within 10 of 8, so what exactly needs to run from -2 (or presumably 0) to 18 in that case?


 
Posted : 14/03/2023 1:46 pm
Posts: 12507
Free Member
Topic starter
 

Within 10 what? 250 isn’t within 10 of 8, so what exactly needs to run from -2 (or presumably 0) to 18 in that case?

Exactly 250 being out of the range 0 to 18 means it's okay that combination can be ignored.

RGB colouring white proper grey and black are matched values.

0,0,0 is black
X,y,z is some value of grey shade if X=y=z
255,255,255 is white

But greyish colours are almost matched.

So I want a list that checks

That checks or builds a list that satisfies these criteria

X=y+-10 AND X=z+-10
Y=X+-10 AND Y=z+-10
Z=X+-10 AND X=y+-10

If they are satisfied they are "almost grey"


 
Posted : 14/03/2023 4:49 pm
 toby
Posts: 532
Full Member
 

OK, I think I get it, so assuming I've read that right and 10, 20, 30 "passes", I think this should do the job...

for (x = 0 ; x <= 255 ; x++) {
_ for (y = max(0, x - 20); y <= min (255, x + 20) ; y++) {
_ _ for (z = max(0, x - 10, y - 10) ; z <= min(255, x + 10, y + 10) ; z++) {
_ _ _ print x . ", " . y . ", " . z . "\r\n";
_ _ }
_ }
}


 
Posted : 14/03/2023 5:15 pm
Posts: 7954
Full Member
 

Can you not just turn the map layer off 🤷.


 
Posted : 14/03/2023 8:37 pm
Posts: 174
Free Member
 

Can you not just turn the map layer off 🤷.

I'd love it if this was the answer! (but I'm sure its more complicated than that)


 
Posted : 14/03/2023 8:57 pm
Posts: 12507
Free Member
Topic starter
 

Can you not just turn the map layer off

It's not a map layer it's a georeferenced pdf.

If I turn it off I can't see anything. Honestly the utilities records in the UK are a disgrace. Incomplete disjointed and basically a cluster of ****ery


 
Posted : 14/03/2023 9:25 pm

6 DAYS LEFT
We are currently at 95% of our target!