*
The moose likes Programming Diversions and the fly likes Cave In Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Cave In" Watch "Cave In" New topic
Author

Cave In

HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Five miners charged out of the shaft of a mine as the timbers caved in behind them.
Jeb was not the first out. Cain was neither first nor last.John Henry pushed out immediately behind Jeb. Preach wasn't second out. Zane was two men behind Preach. In what order did the men race from the mine ?

And another.....



Place the numbers from 1 to 6 in the circles of the triangle so that the numbers in every circle below two higher circles show the difference between the two numbers in the higher circles.
How should the numbers be positioned to show this ?
regards
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I won't show my answer to the first question yet, but I'll add a followup: how much information can you delete from the original question and still end up with the same unique answer?
For the second question, I don't know how many solutions there are, but here are several:

Those were easy enough to find that I suppose the next step is for someone to write a program to find all solutions; I'll let someone else do that.


"I'm not back." - Bill Harding, Twister
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

A Jess solution:

And executing it gives:


[Jess in Action][AskingGoodQuestions]
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

interesting JESS code -- I'd never seen any "In action"
I didn't write code for the 1st question -- but yay I got it right.
I got this variation for the 2nd question:


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
An interesting Jess Rules application and the correct answer.
There seem to be only four combinations to the second question, those listed by Jim and Jess. (Ah! That's a name crying out for a pre-schooler book like Janet and John. Note how the order is important- John and Janet and Jess and Jim won't sound right. It's a rhyming thing. I presume John and Jess have more rhyming potential tucked at the end. That's another for Tim Allen )
To restate the second problem to make it easier to write a program.
Construct pyramids of n-numbers in sequence where the numbers in a position below two higher positions shows the difference between two numbers in the higher positions. The n-th number must be in the top row since it is not the difference between any two other numbers.
Try it out with n-th numbers of 3,6,10,15; the first two have 2 and 4 solutions respectively.
Lots of valid sequences for 10 which always fail on the last number- ?

But I finally got this : hurray!


I suspect for 15 you'd have to start the pyramid at 6 to release the smaller numbers into the pool.


regards
[ October 26, 2003: Message edited by: HS Thomas ]
Timothy Chen Allen
Ranch Hand

Joined: Mar 16, 2003
Posts: 161
I wrote a dumb little Swing program to let me play with this problem. This program doesn't actually produce an answer, it just let's you try out different solutions.
It produces a tiny inverted triangle of textfields. Only the top row is editable, changes there ripple down. If you reach a good solution, the top row goes green, otherwise it goes red.
I'll see if I can write the one that finds all the solutions (probably shouoldn't be all that hard).


Timothy Chen Allen
Learn Spanish in Washington, DC
Timothy Chen Allen
Ranch Hand

Joined: Mar 16, 2003
Posts: 161
Here is a BRUTE FORCE method for finding solutions for the pyramid problem. It's awful. The only performance gain I got was from realizing that I could just set the top three numbers and then calculate the rest of the pyramid.
I suppose this could be extended to allow for larger pyramids, but that would just extend the awfulness of this solution.
Anyway, here's the code:

And here are the solutions:
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
#Absolutely
#I should have added that there should be no reflections .#( #I dropped coffee on my keyboard so it's typing funny. #I cannot get rid of this ghost#)

#But it's cool that a program can get the reflections as well whereas a human can do them automatically.
regards
Timothy Chen Allen
Ranch Hand

Joined: Mar 16, 2003
Posts: 161
Originally posted by HS Thomas:

#But it's cool that a program can get the reflections as well whereas a human can do them automatically.
regards

An excellent observation about the comparative abilities of humans and computers. For the computer to see that a pyramid adds up correctly is a simple operation, whereas this operation for a human may require substantial thought and even (in the case of my wife) paper and pencil!
Seeing the symmetry of an object is dead simple for a human, but for a computer it would be hard work. And a human can identify the symmetry of an object even if it is only partially symmetrical. Consider the teapot-- a human would figure out easily that the main body is a symmetrical object, and that it had some non-symmetrical features (the handle and spout). But a computer would have to have a very extensive program to do this, and could be thrown off by seemingly minor inconsistencies.
On the other hand, our wetware probably has just such a complex "program" built in over years and years of observing objects.
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404

An interesting twist to the above.
Arrange the numbers from 1 to 6 in the triangle so that the sum of each straight line of three circles gives the same result. How would you place the numbers ? Switch and swap explorations will yield four unique solutions excluding rotations and reflections.

(I would try combining the two problems in one program. Using Jess would help breaking the rules so that they could be used in both problems, I think . Pity my book hasn't arrived and no trace of a distributor )
regards
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
I'd think you could switch and swap on three numbers at a time.
For one problem , explore the differences, for the other explore the sum.
Then switch and swap again if it didn't work. If the program remembers rotations and reflections then it wouldn't go down the route again.

regards.
[ November 07, 2003: Message edited by: HS Thomas ]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

I got the Sums answer by placing the low numbers counter-clock-wise ath the points
[CODE]
1 X 3
X X
2
[CODE]
and then filled in the high numbers counter-clock-wise in the center
[CODE]
1 5 3
6 4
2
[CODE]
I made sure that the 6 (highest high number) was in the same line as the 1-2 (lowest combination of low numbers) and filled in from there.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Right , Joel.
There are three more, at least.
regards
 
Consider Paul's rocket mass heater.
 
subject: Cave In
 
Similar Threads
9 1 1
Big O notation
Any suggestions please!!
Hindus involved in Spain terrorism??
Help in Algorithm Construction