Hi, I am looking to write a short code to compare values in an array.
For example, I want to have a list of values in a text file and then have each value compared to all of the other values to find out which ones are within 8 of each other.
Example: 8, 9, 20, 22, 40, 39. Answer would be that the group of 8 and 9 and 20 and 22 would be within 8 of each other.
I have no real world programming experience. I imagine this should be a simple task.
Yes, it should be a simple task. The best suggestion I could give would be to sort the values so that you don’t have to compare each to all of the others.
If given the integers 1 to 32 in some order, would the grouping depend on the order? What makes a usable grouping for you as your numbers you provide would work with more than one grouping method, but my suggested numbers could give multiple answers specific to the grouping method chosen.