Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 7th, 2011, 02:03 PM
Juliusbk Juliusbk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2011
Posts: 2 Juliusbk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 59 sec
Reputation Power: 0
Question Least Moves Algorithm

My problem is this:

Suppose you have N urns that contain iron of a different weights (floating points). I need to cut iron from urns and throw it into other urns until each urn contains equal amounts of iron. I need an algorithm that tells me how much iron to take from which urn and which urn to put it into.

Of course this problem has several solutions; and I can think of some algorithms. But I am asking you for some good algortihms - hopefully an algortimh that gives the solution(s) which requires least moves.


I hope I've been clear enough, but let me, just to be sure, give an example:

Urn 1: 10 kg.
Urn 2: 0 kg.
Urn 3: 3 kg.
Urn 4: 7 kg.

A 'good' solution to this is:

Take 5 kg. from urn 1 and put into urn 2.
Take 2 kg. from urn 4 and put into urn 3.

I don't necessarily need exhaust algorithm that gives me all solutions. That would of course be best, but actually I only need one solution as long as it is optimal (least moves).


Thank you very much in advance.

Reply With Quote
  #2  
Old July 7th, 2011, 05:55 PM
requinix's Avatar
requinix requinix is offline
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,864 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 5 h 56 m 54 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Do you know how to determine which one has the fewest moves?

(I know an average case ~N/2 and worst case N-1 algorithm, but I don't know if it's optimal)

Last edited by requinix : July 7th, 2011 at 05:59 PM.

Reply With Quote
  #3  
Old July 8th, 2011, 09:13 AM
Juliusbk Juliusbk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2011
Posts: 2 Juliusbk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 59 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
Do you know how to determine which one has the fewest moves?

(I know an average case ~N/2 and worst case N-1 algorithm, but I don't know if it's optimal)


No, I wish I did.

My best bet is simply taking the urn with most iron and filling from this into the one with least, and constantly repeating this.

I would like to see your best algorithm, just for inspiration...

Reply With Quote
  #4  
Old July 8th, 2011, 01:33 PM
requinix's Avatar
requinix requinix is offline
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,864 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 5 h 56 m 54 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
That's it, actually: take from the most and give to the least.
Code:
3 1 4 1 5 9 2 6 5
  ^       ^
3 4 4 1 5 6 2 6 5
      ^   ^
3 4 4 4 5 3 2 6 5
            ^ ^
3 4 4 4 5 3 4 4 5
^       ^
4 4 4 4 4 3 4 4 5
          ^     ^
4 4 4 4 4 4 4 4 4

Given M=the number of urns that need adjustment, the lower bound on the number of moves is ceil(M/2) (1 3 1 3) and the upper bound is M-1 (1 1 1 5).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Least Moves Algorithm

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap