473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

c++ math algorithm

Good day. My semester of c++ is coming to an end. I've got to complete a total of 7 assignments within the next 3 weeks. I've completed 5 out of the seven. I've got two left (1 has a separate thread by itself). So you can also take a look at it. This is the assignment:
STOLEN GOLD SHIPMENT MYSTERY
Three gangsters rob a shipment of gold bars late one night. They
escaped to their hideout and resolved to divide the loot in the
morning.
However, as soon as one of the bandits heard the others snoring, he
divided the gold into three equal piles, finding one bar left over. He
buried one of the three piles near a tree along with the extra bar.
Then he went to sleep, sure that he had protected his interest in the
treasure.
Naturally, the other two outlaws were no more honest than the first.
Each in turn crept to the pile of gold bars, divided it three ways and
found one bar left over, which he kept along with "his" third of the
treasure.
Soon, morning came and the final three—way division. Oddly enough,
this division also left one odd bar remaining. The bandits fought over
this bar, and in an unprecedented three—way draw, shot each other
dead.
The problem is this:
Each of the four 3-way divisions left exactly one bar. How many bars
could have been in the original shipment. Assume that the shipment
contained no more than 500 bars.

No arrays/functions are necessary. So if someone could give me a jumpstart or how you'd go about addressing it, that would be appreciated. Thank you and have a good day.
Nov 8 '07 #1
2 2311
Laharl
849 Expert 512MB
If you're having trouble getting started with your code, see if you can work it out on paper first.
Nov 8 '07 #2
Ganon11
3,652 Expert 2GB
So you had some total, N, gold to start. When it was divided by three, the remainder was one. Let's call the new sum (which is N/3) N1. Then N1 was divided by 3, and again the remainder was 1. Let's call the new sum (which is N1/3) N2. Again, N2 is divided by 3, and 1 is the remainder. Let's call the new sum (which is N2/3) N3. Finally, N3 is divided by 3, and 1 is the remainder. So each pile had a total of G/3 (where G == N3/3) gold, and there was 1 extra. From here, I think it would be simple to find out the total. Just find the total remaining above ground, then repeat these steps to find N2, N1, and finally, N.
Nov 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Murat Tasan | last post by:
here is the situation... i have an array... and i select something from random from it. i pick a random number x by using Math.random() and multiplying it by the length of the array. but this...
4
by: Robert Scheer | last post by:
Hi. Reading about the Math.random method I saw that by default it generates between 0 and 1. To generate numbers between a greater range I can use these syntaxes: x = Math.random()/10 x =...
23
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you...
12
by: xeys_00 | last post by:
I decided I need to understand math more to help me with programming. Not to mention, eventually in my degree plan I will need to do it anyway. How much math have people in this forum taken, and...
6
by: RobG | last post by:
I am writing a script to move an absolutely positioned element on a page by a factor using style.top & style.left. The amount to move by is always some fraction, so I was tossing up between...
2
by: ben | last post by:
hello, i'm following an algorithm book and am stuck on an early excersise in it, not because of the c programming side of it or even the algorithm side of it, i don't think, but because of maths....
5
by: Ark | last post by:
Hi everyone, Does anyone know if Direct3D overloads System.Math functions? Also is it possible to access the base functions of the overloaded function (in other words restore original of the...
110
by: Gregory Pietsch | last post by:
I'm writing a portable implementation of the C standard library for http://www.clc-wiki.net and I was wondering if someone could check the functions in math.h for sanity/portability/whatever. I'm...
15
by: Morgan Cheng | last post by:
Hi, I am writing a program that will take a lot of Math.Cos & Math.Sin operation. I am afraid this will be source of performance impact. Anybody knows how Math.cos & Math.Sin is implemented?...
34
by: Johannes Baagoe | last post by:
About Math.random(), ECMA 262 just says "Returns a number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.