ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What do you mean by "Create programm (sic) to verify..."? Might there be other sequences of integers 1 thru 32 that work? Might there be other limits other than 1 thru 32?
What do you mean by "Create programm (sic) to verify..."? Might there be other sequences of integers 1 thru 32 that work? Might there be other limits other than 1 thru 32?
Problem is to implement effectively "circle" as data structure - or ring. There is no "first" or "last" element in "circle".
Problem is to implement effectively "circle" as data structure - or ring. There is no "first" or "last" element in "circle".
That's not a problem any more than drawing a circle on paper is a problem - just pick any arbitrary position to begin at, and connect back to that point.
What's the context of this? Is it homework, a learning exercise, just a curiosity, or something else?
Problem is to implement effectively "circle" as data structure - or ring. There is no "first" or "last" element in "circle".
Perhaps i still don't understand your question, but it doesn't sound difficult. To operate on a 'ring' of data, you would have to start at some (random?) point on the ring, and proceed either clockwise or counter-clockwise until you returned to the starting point.
Programmatically, this could be achieved by defining the ring as a simple array, and then, starting from a random offset, process in a linear manner, logically wrapping around to the array's first element as needed, continuing until you return to the starting offset. For counter-clockwise, process in reverse order.
But here's an interesting programming challenge: Given the requirements that the numbers 1 thru 32 must exist exactly once, and that the sum of each adjacent pair of numbers must be a perfect square, write a program to generate a ring of data. The above methodology could be employed to do so, and to compare the sequence(s) generated against the ring of data shown in the jpg image.
While i was typing the above, danielbmartin supplied a program. My previous post tells how to treat the data as a 'ring'. Start at a random offest, and wrap as needed.
Note: You'd have to increase the for loop by one step, to connect the first and last element in the 'ring'.
Last edited by dogpatch; 04-04-2021 at 04:09 PM.
Reason: add note
Well. . . not exactly. It merely adds an element to the linear array, with the added last element equal to the first. Same result, but not quite the same as wrapping around to form a logical ring.
Well. . . not exactly. It merely adds an element to the linear array, with the added last element equal to the first. Same result, but not quite the same as wrapping around to form a logical ring.
Problem is to implement effectively "circle" as data structure - or ring. There is no "first" or "last" element in "circle".
Your program works, but treats the data as a linear array. The better way to answer the OP would be to define a class 'Ring', in which processing could begin at any arbitrary point in the ring, and wrap around in a circular manner. In a non-oop program, you could still use a linear array, but allow processing to begin at any point in the array, and wrap around to the beginning as needed.
Post #1 in this thread asked for a program to test the validity of a Magic Circle. Quoting from the image in that post, "the sum of any two adjacent numbers is a perfect square."
Testing this assertion does not require any specific starting point, nor does it demand a direction of travel (clockwise or counterclockwise). If all number pairs sum to a perfect square the number sequence is validated.
Post #7 introduces the word random. That was not stipulated in post #1 nor does it strengthen the validation demonstrated by the solution offered in post #6. If every number pair sums to a perfect square, that is true regardless of travel direction or starting point.
A favorite maxim: "Don't make the job harder than it has to be."
verifying that circle is not an issue. You can do it without computer, calculator or any other tool in minutes (entering the numbers into any device will take longer than the check).
The "real" problem is to generate a circle like this. How many different amazing circle exist?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.