tag:blogger.com,1999:blog-16805286.post892153916866155203..comments2019-07-06T16:33:35.606+05:30Comments on ScribblinG: Puzzle: Help JimVijeshhttp://www.blogger.com/profile/18155433751670204131noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-16805286.post-62107977649002042142011-02-18T12:44:04.975+05:302011-02-18T12:44:04.975+05:30@Ramkumar Yup that was a bug, thanks for pointing ...@Ramkumar Yup that was a bug, thanks for pointing it.Vijeshhttps://www.blogger.com/profile/18155433751670204131noreply@blogger.comtag:blogger.com,1999:blog-16805286.post-81195662909586195352011-02-18T12:29:34.664+05:302011-02-18T12:29:34.664+05:30Correct me if I am wrong, but Vijesh, should not t...Correct me if I am wrong, but Vijesh, should not the code have another line: <br />reminder = a%b, after you reinitialize a as a = reminder*10 ;<br /><br />Otherwise no matter what the loop will run only once because reminder is already added to the Hash Set.Ramkumarhttps://www.blogger.com/profile/09677486810553712944noreply@blogger.comtag:blogger.com,1999:blog-16805286.post-88100693175303883312011-02-15T20:07:33.060+05:302011-02-15T20:07:33.060+05:30Spot on Vijesh - the same remainder is the key. :)...Spot on Vijesh - the same remainder is the key. :)The Visitorhttps://www.blogger.com/profile/06379204603893147923noreply@blogger.comtag:blogger.com,1999:blog-16805286.post-33845916209708788222011-02-15T15:48:31.340+05:302011-02-15T15:48:31.340+05:30Finding Q would be straight forward. Now for the r...Finding Q would be straight forward. Now for the reminder part (D), keep iterating until the reminder number reccurs, that will help in identifying the recurring decimal number.<br />Something like 4/3 will give 1 as reminder first, then again it will give reminder 1. So how many times we repeatedly divide 1 it will give the same recurring pattern. For this one needs to remember the reminders that occurred previously.<br /><br />HashSet hSet = new HashSet();<br />int reminder = a%b;<br />while(!hSet.contains(reminder)) {<br /> hSet.add(reminder);<br /> a = reminder * 10;<br />}<br /><br />Let me know if there is a better solution.Vijeshhttps://www.blogger.com/profile/18155433751670204131noreply@blogger.comtag:blogger.com,1999:blog-16805286.post-38844337234689501622011-02-13T14:35:38.825+05:302011-02-13T14:35:38.825+05:30If
A / B = Q.D
where a and b are 2 + integers
Q...If<br /><br /> A / B = Q.D<br /><br />where a and b are 2 + integers<br />Q is the integer part of the result and D the decimal part of the result.<br /><br />Prob spec. Write a program that will accept 2 integers A and B as input and print Q.D and terminate with a newline. If D is a recurring decimal print the recurring part only once.<br /><br />examples:<br />a=10 b=5 Q.D = 2.0<br />a=5 b=2 Q.D = 2.5<br />a=10 b=6 Q.D = 1.6<br />a=7 b=6 Q.D = 1.16<br /><br /><br />Pseudocode is fine, C or Java for implementation.The Visitorhttps://www.blogger.com/profile/06379204603893147923noreply@blogger.comtag:blogger.com,1999:blog-16805286.post-68982454753330633082011-02-13T11:18:11.470+05:302011-02-13T11:18:11.470+05:30The Visitor, that's right.The Visitor, that's right.Vijeshhttps://www.blogger.com/profile/18155433751670204131noreply@blogger.comtag:blogger.com,1999:blog-16805286.post-38595698060293219942011-02-12T21:42:12.650+05:302011-02-12T21:42:12.650+05:30Correction:
... in a sequence of 3 continuous numb...Correction:<br /><i>... in a sequence of 3 continuous numbers atleast one will be divisible by 3 ...</i><br /><br />to be read as:<br /><br />... in a sequence of 3 continuous numbers one will be divisible by 3 ...The Visitorhttps://www.blogger.com/profile/06379204603893147923noreply@blogger.comtag:blogger.com,1999:blog-16805286.post-78382928714220592692011-02-12T21:35:37.751+05:302011-02-12T21:35:37.751+05:30That the number will be divisible by 2 is obvious,...That the number will be divisible by 2 is obvious, because every 2nd number will be divisible by 2. As the previous and next numbers are primes the middle number will be divisible by 2.<br /><br />Similarly the number will be divisible by 3 because in a sequence of 3 continuous numbers atleast one will be divisible by 3. By the same argument as above the middle number will be divisible by 3. <br /><br />Any number divisible by both 2 and 3 <i>will</i> be divisible by 6.The Visitorhttps://www.blogger.com/profile/06379204603893147923noreply@blogger.com