The Artima Developer Community
Sponsored Link

Java Answers Forum
Arrghhhh plz plz help

1 reply on 1 page. Most recent reply: Nov 19, 2003 10:50 AM by Kishori Sharan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Tony

Posts: 3
Nickname: maximus
Registered: Oct, 2003

Arrghhhh plz plz help Posted: Nov 19, 2003 7:18 AM
Reply to this message Reply
Advertisement
Any ideas



There is a medieval puzzle about an old woman and a large basket of eggs. On her way to market, a horseman knocks down the old woman and all the eggs are broken. The horseman will pay for the eggs, but the woman does not remember the exact number she had, only that when she took the eggs in pairs, there was one left over; similarly, there was one left over when she took them three, four, five, or six at a time. When she took them seven at a time, however, she came out even.

Write a Java program to determine the smallest number of eggs the woman could have had.


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: Arrghhhh plz plz help Posted: Nov 19, 2003 10:50 AM
Reply to this message Reply
You don't need to appy the condition taht when taken in pair then one is left over. Because, if taken 4 then one is remaning then when taken in 2 will always leave one. Same goes with taken 3 and 6 at a time. Answer is 301.
public class Egg {
	public static void main(String[] args) {
		
		for ( long counter = 7; counter < Long.MAX_VALUE; counter +=7 ) {
			if ( counter % 4 == 1 &&   
 			    counter % 5 == 1 &&
			    counter % 6 == 1 &&
			    counter % 7 == 0 ) {
			 System.out.println ( "No of eggs:" + counter ) ;
			 break;
			}
		}
	}
}

Flat View: This topic has 1 reply on 1 page
Topic: Radix sort Previous Topic   Next Topic Topic: file handling errors

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use