IntelliJ Java IDE
The moose likes Programming Diversions and the fly likes Arrange the numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Reply Bookmark "Arrange the numbers" Watch "Arrange the numbers" New topic
Author

Arrange the numbers

Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1828
This one is simpler:
Arrange the numbers from 1 to 9(1 & 9 inclusive) along a circle such that sum of two neighbors is NEVER divisible by 3,5,7.


MH
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
Finding the solution isn't too hard, but I found that the question afforded me an opportunity to write some code in ML to get some practice.
The solution can be found with this SML code. It's quite snappy for this problem, however it's not all that scalable overall due to the problem constraints. I represent the problem as a graph and attempt to find a Hamiltonian cycle, which is an NP problem.
Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1828
Havn't gone through thr program.Hamiltonian Path soln. is right.We can start with any digit and connect to another digit by given condition.I made a table containing digit and its possible neighbors.and started with digits which has least number of neighbors.
Karthikeyan Rajendraprasad
Ranch Hand

Joined: Apr 16, 2003
Posts: 70
the solution is

got it manually.......... still trying to find the same solution using a program
[ February 24, 2004: Message edited by: Karthikeyan Rajendraprasad ]

Karthikeyan<br />SCJP 1.4, SCWCD.
 
 
subject: Arrange the numbers
 
Threads others viewed
Help in using Regular Expression
algoritem writing problem
JavaScript RegEx
Finding the Median
Java regular expressions for value ranges
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com