Piano Forum

Topic: Riddle (computer scientists, eat your hearts out)  (Read 1902 times)

Offline allchopin

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 1171
Riddle (computer scientists, eat your hearts out)
on: October 07, 2004, 11:12:05 PM
Here's the riddle... I don't have the solution but I'm hoping someone could offer ideas.

There are a given number of people, and a given number of boxes (# boxes > #people).  Each box contains different numbers of rocks, each given as well.  How would you distribute the boxes of rocks so that each person gets the closest number of rocks as everyone else (within a given threshold of deviation)?  

Example:  There are two people, three boxes.  In the three boxes there are 3 4 and 5 rocks.  The distribution would be the 3- and 4- rock boxes to one person and the 5-rock box to the other, making a difference of only 2 (7-5).

A program to do such is the eventual goal!
A modern house without a flush toilet... uncanny.

Offline bernhard

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 5078
Re: Riddle (computer scientists, eat your hearts o
Reply #1 on: October 08, 2004, 01:05:39 AM
So, now we are supposed to do your course assignments as well?

;D ;)
The music business is a cruel and shallow money trench, a long plastic hallway where thieves and pimps run free, and good men die like dogs. There's also a negative side. (Hunter Thompson)

Offline squinchy

  • PS Silver Member
  • Full Member
  • ***
  • Posts: 227
Re: Riddle (computer scientists, eat your hearts o
Reply #2 on: October 08, 2004, 04:54:38 AM
Are the number of rocks in the boxes always consecutive, and is there a required percentage of people that must have at least one box? Also, what language is this to be in?

[My only progamming skill is getting lots of coloured dots to appear on a screen using QBASIC, but perhaps I can help with the algorithmic part of it.]
Support bacteria. They're the only type of culture some people have.

Offline allchopin

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 1171
Re: Riddle (computer scientists, eat your hearts o
Reply #3 on: October 08, 2004, 05:04:55 AM
Quote
So, now we are supposed to do your course assignments as well?

And I get all the credit.  ;D

I suppose I should've specified a little more clearly.. the number of boxes people can get can be zero or it could be a million.  The number of rocks in each is completely arbitrary, and is simply given data.
And if you're able to find a solution, I don't care what language it is in.  English is the bare minimum  :D.
A modern house without a flush toilet... uncanny.

Offline squinchy

  • PS Silver Member
  • Full Member
  • ***
  • Posts: 227
Re: Riddle (computer scientists, eat your hearts o
Reply #4 on: October 11, 2004, 12:23:39 AM
Hm..

How about "lining up" (you can consider all action verbs and their objects henceforth in quotes, since they're more actions by the computer and not by the human) all the boxes in ascending order. Then, count the number of boxes. If the number is even, set no boxes aside, if the number is odd, set one box aside (at random).

Pick two people to receive the boxes at random. Person one will take the two boxes at the end of the line, then Person two will do the same. Repeat until all boxes are taken, and then give the box that was set aside to the person with least number of boxes. If both people have the same number, give it to the person with least number of rocks. If that's the same, then I don't know what to do.

..That plan has about 80 glaring faults that I can see and probably 800 that I can't, but it's in English, and it may have a 50% chance of success.
Support bacteria. They're the only type of culture some people have.

Shagdac

  • Guest
Re: Riddle (computer scientists, eat your hearts o
Reply #5 on: October 11, 2004, 05:30:45 AM
Allchopin wrote:

Quote
How would you distribute the boxes of rocks so that each person gets the closest number of rocks as everyone else


then...
Quote
the number of boxes people can get can be zero or it could be a million.


ANSWER:  Give both of the 2 people zero boxes!
Then they both have NO rocks. That's about as close as you can get! ;D ;D

S :)

Offline allchopin

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 1171
Re: Riddle (computer scientists, eat your hearts o
Reply #6 on: October 11, 2004, 07:01:01 PM
Sorry - you have to give them all out.  That would be a bit too easy for $500 wouldn't it?  ;)
A modern house without a flush toilet... uncanny.

Offline Saturn

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 271
Re: Riddle (computer scientists, eat your hearts o
Reply #7 on: October 11, 2004, 07:10:34 PM
Quote
Sorry - you have to give them all out.  That would be a bit too easy for $500 wouldn't it?  ;)


The problem is worth $500?  Where can I find out more about this?

Offline squinchy

  • PS Silver Member
  • Full Member
  • ***
  • Posts: 227
Re: Riddle (computer scientists, eat your hearts o
Reply #8 on: October 11, 2004, 09:09:13 PM
Quote


The problem is worth $500?  Where can I find out more about this?


0_o So either your coursework pays, or you're in a programming contest?
Support bacteria. They're the only type of culture some people have.

Offline super_ardua

  • PS Silver Member
  • Full Member
  • ***
  • Posts: 164
Re: Riddle (computer scientists, eat your hearts out)
Reply #9 on: October 14, 2004, 10:18:50 AM
Ok let's process the facts.

Try getting every permutation first then see which produces the smallest difference in rocks.

Then optimise it from there on.

or

find the average amount of rocks per person,  then say everyone has to have at last one box? no.  well give everyone a box at random,  check how close we are to the average,  then if someone is higher than the avreage, give everbody a box?  no,  because ....


ok lets try a different approach
         
PeopleOddOddEvenEven
RocksOddEvenOddEven


We'll need a diffent subroutine for each:

P: odd Rocks : even

Well average is (2n + 1) / 2n so you're not going to get an integer answer so what are you going to do?  How many people do you want over the average? Iyou allocate a large box to someone,  you wnt the next one to be small.  think about


I have given enough clues.  Work it out yourself
We must do,  we shall do!!!

Offline allchopin

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 1171
Re: Riddle (computer scientists, eat your hearts out)
Reply #10 on: October 14, 2004, 03:26:14 PM
Try getting every permutation first then see which produces the smallest difference in rocks.
Well, yes, this is easy to say.  However, I neglected to mention that the program pretty much needs to be instantaneous and should run in about one second.  A computer and 100 factorial for-loops don't mix.
Quote
Then optimise it from there on.
How?

Quote
find the average amount of rocks per person,  then say everyone has to have at last one box?
Everyone will eventually get a box, but they technically don't have to.  Yet that'd be pretty dumb because the number of boxes is always greater than the number of people, so not giving a person a box would be a wrong answer for sure.

Quote
then if someone is higher than the avreage, give everbody a box?  no,  because ....
...Because people CAN be higher than the average.  What matters is that the DIFFERENCE between the highest and lowest must be a small number.  So some will be higher and some will be lower.

Quote
         
PeopleOddOddEvenEven
RocksOddEvenOddEven
We'll need a diffent subroutine for each:

P: odd Rocks : even

Well average is (2n + 1) / 2n so you're not going to get an integer answer so what are you going to do?  How many people do you want over the average? Iyou allocate a large box to someone,  you wnt the next one to be small.  think about
Hmm.
Not sure what you mean here..  an odd box should be given to people with even numbers os rocks?  And what do you mean by 'How many people do you want over the average'?  I don't think shooting for an average is the best way, because I found that way to be a dead end.  I think the iterations is the only way to do it, but making it fast and efficient, as well as optimised is what is difficult.
A modern house without a flush toilet... uncanny.

Offline super_ardua

  • PS Silver Member
  • Full Member
  • ***
  • Posts: 164
Re: Riddle (computer scientists, eat your hearts out)
Reply #11 on: October 14, 2004, 05:42:45 PM
those were half boiled ideas.  Ignore them if you may
We must do,  we shall do!!!

Offline super_ardua

  • PS Silver Member
  • Full Member
  • ***
  • Posts: 164
Re: Riddle (computer scientists, eat your hearts out)
Reply #12 on: October 14, 2004, 05:57:15 PM
Crikey, this is hard.

If the approach you're working with doesn't work, it is worng so,

1. Permutations - Too slow
2. Aiming for an average? no

So you must think how we try to do it in our heads.

Facts:(check validity)

1. Not everone will have a box
2. As the total number of boxes increases to infinity, the minumum difference will decrease
3. As #people----->#boxes Minumum difference increases


Questions :

1. What does the smallest possible diference depend on?
    a) Does it increase with the number of stones in each box? No
    b) Number of people? Not really

So apart from burte force another way may to compute the minumum difference possible. But how? Dead end

Try Arranging the Boxes according to the number of rocks in them then matching the ones which contain least to most. Then arrange these pile of boxes in order of total stones in them. Match boxes higher number of stones to lower amount of stones. Until you have more piles than amount of people. Divide the pile of boxes in which each boxes has small number of stones into roughly the mount of people you have and share.  Voila ! Improve slightly on that and you may have your solution!!!!!!!!!!!
We must do,  we shall do!!!
For more information about this topic, click search below!

Piano Street Magazine:
New Piano Piece by Chopin Discovered – Free Piano Score

A previously unknown manuscript by Frédéric Chopin has been discovered at New York’s Morgan Library and Museum. The handwritten score is titled “Valse” and consists of 24 bars of music in the key of A minor and is considered a major discovery in the wold of classical piano music. Read more
 

Logo light pianostreet.com - the website for classical pianists, piano teachers, students and piano music enthusiasts.

Subscribe for unlimited access

Sign up

Follow us

Piano Street Digicert