LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-03-2021, 08:49 AM   #1
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
amazing circle


Create programm to verify this circle is really amazing for perfect square just google
Attached Thumbnails
Click image for larger version

Name:	amazing-circle.jpg
Views:	82
Size:	56.1 KB
ID:	36019  
 
Old 04-04-2021, 11:20 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,427
Blog Entries: 1

Rep: Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679
That's amazing, indeed.
 
Old 04-04-2021, 12:47 PM   #3
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
Cool.

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?
 
Old 04-04-2021, 02:57 PM   #4
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717

Original Poster
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
Quote:
Originally Posted by dogpatch View Post
Cool.

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".
 
Old 04-04-2021, 03:37 PM   #5
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,064

Rep: Reputation: 2165Reputation: 2165Reputation: 2165Reputation: 2165Reputation: 2165Reputation: 2165Reputation: 2165Reputation: 2165Reputation: 2165Reputation: 2165Reputation: 2165
Quote:
Originally Posted by igadoter View Post
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?

 
Old 04-04-2021, 03:40 PM   #6
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,856

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
With this one-line InFile ...
Code:
1 8 28 21 4 32 17 19 30 6 3 13 12 24 25 11 5 31 18 7 29 20 16 9 27 22 14 2 23 26 10 15 1
... this awk ...
Code:
awk  \
  'BEGIN{SqTab=1 4 9 16 25 36 49 64 81 100}    # Build a table of perfect squares.
     {for (j=1;j<=32;j++)                      # 32 number pairs to be tested.
       {sum=$j+$(j+1)                          # Add an adjacent pair of numbers.
        print j,$j"+"$(j+1)"="sum              # Show result.
        if (index(SqTab,sum)==0) print "FAIL!" # Handle FAIL case.
     }}' $InFile >$OutFile 
cat $OutFile
... produced this OutFile ...
Code:
1 1+8=9
2 8+28=36
3 28+21=49
4 21+4=25
5 4+32=36
6 32+17=49
7 17+19=36
8 19+30=49
9 30+6=36
10 6+3=9
11 3+13=16
12 13+12=25
13 12+24=36
14 24+25=49
15 25+11=36
16 11+5=16
17 5+31=36
18 31+18=49
19 18+7=25
20 7+29=36
21 29+20=49
22 20+16=36
23 16+9=25
24 9+27=36
25 27+22=49
26 22+14=36
27 14+2=16
28 2+23=25
29 23+26=49
30 26+10=36
31 10+15=25
32 15+1=16
Daniel B. Martin

.
 
1 members found this post helpful.
Old 04-04-2021, 04:01 PM   #7
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
Quote:
Originally Posted by igadoter View Post
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.
 
Old 04-04-2021, 04:05 PM   #8
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
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
 
Old 04-04-2021, 04:44 PM   #9
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,856

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Quote:
Originally Posted by dogpatch View Post
... Note: You'd have to increase the for loop by one step, to connect the first and last element in the 'ring'.
The published solution does close the ring.

Daniel B. Martin

.
 
Old 04-05-2021, 09:10 AM   #10
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
Quote:
Originally Posted by danielbmartin View Post
The published solution does close the ring.

Daniel B. Martin

.
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.
 
Old 04-05-2021, 10:43 AM   #11
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,856

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Quote:
Originally Posted by dogpatch View Post
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.
I fail to see the distinction. Please explain.

Daniel B. Martin

.
 
Old 04-05-2021, 01:00 PM   #12
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
In post #4, OP was asking
Quote:
Originally Posted by igadoter View Post
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.
 
Old 04-05-2021, 01:08 PM   #13
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
I may post a small C++ program to illustrate what i mean. But am out of connection minutes, so will wait until another day.
 
Old 04-06-2021, 09:48 AM   #14
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,856

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
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."

Daniel B. Martin

.
 
Old 04-06-2021, 11:33 AM   #15
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 19,545

Rep: Reputation: 6622Reputation: 6622Reputation: 6622Reputation: 6622Reputation: 6622Reputation: 6622Reputation: 6622Reputation: 6622Reputation: 6622Reputation: 6622Reputation: 6622
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?
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
RPM - dependencies going round in circle! The_JinJ Linux - Newbie 6 11-23-2004 05:09 AM
NDISWrapper and the circle of Hate ryanroler Linux - Wireless Networking 3 11-06-2004 09:55 PM
going in circle's with fstab and cd-rom chopp Linux - Newbie 32 10-08-2003 08:08 AM
Confusion with RPM's - vicious circle mykyl Linux - Software 13 09-18-2003 03:48 PM
Draw Circle Gerardoj Programming 11 08-24-2003 06:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration