+ Reply to Thread
Results 1 to 3 of 3

trivia question- moving marbles from jars in a few a moves as possible! :)

Hybrid View

  1. #1
    Registered User
    Join Date
    08-09-2016
    Location
    Glasgow
    MS-Off Ver
    2016
    Posts
    2

    trivia question- moving marbles from jars in a few a moves as possible! :)

    Hello

    Im currently trying to use excel with a trivia question.

    I have 7 jars with a random but known quantity of marbles in them. I also know the total number of marbles in all the jars. Now, im trying to find a way that with one move per jar (or less), I can ensure an equal number of marbles in each jar.

    for example,

    Jar A, B, C, D, E, F, G have the respective number of marbles: 10, 30, 50, 5, 30, 105, 225 meaning the total number of marbles are 455. This means each jar should have 65 marbles in them.
    Is there any way I can ensure this, with 7 or less moves. the number of marbles, and jars can also change so trying to find an equation that will work for a variety of options

    ideally something like, Move 50 marbles from jar A to C, move 2 marbles from jar D to A, move 20 from F to A etc. looking for the calculation that I could use to help with the scenarios. I don't have the number of jars or final marbles yet, just trying to get prepared
    thanks in advance!!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: trivia question- moving marbles from jars in a few a moves as possible! :)

    Hi, and welcome to the forum.

    Does the following macro (also attached) help?

    Sub MoveMarbles()
        Dim lJars As Long, arJars() As Variant, st As String, st2 As String, lOrig As Long
        Dim  lTotal As Long, lAverage As Long, x As Long, y As Long, lPot As Long
    
        arJars = Sheet1.Range("A1").CurrentRegion
        lJars = UBound(arJars)
    
        For x = 1 To lJars
            lTotal = lTotal + arJars(x, 1)
        Next x
    
        lAverage = lTotal / lJars
    
    
        For x = lJars To 1 Step -1
            If arJars(x, 1) > lAverage Then
                lOrig = arJars(x, 1)
                lPot = lPot + arJars(x, 1) - lAverage
                st = st & " Take " & arJars(x, 1) - lAverage & " marbles from the pot with " & lOrig & " marbles,"
                arJars(x, 1) = lAverage
    
            Else
                lOrig = arJars(x, 1)
                lPot = lPot - arJars(x, 1)
                st2 = st2 & " put " & lAverage - arJars(x, 1) & " in the pot with " & lOrig & " marbles,"
                arJars(x, 1) = lAverage
            End If
    
        Next x
        Range("c1") = st & " " & st2
    
    End Sub
    Attached Files Attached Files
    Last edited by Richard Buttrey; 08-09-2016 at 10:23 AM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    08-09-2016
    Location
    Glasgow
    MS-Off Ver
    2016
    Posts
    2

    Re: trivia question- moving marbles from jars in a few a moves as possible! :)

    great!
    i'll give it a try. what a helpful forum this is

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro Help: When moving a row, it moves the row to the top rather than bottom
    By PlaceboGraeme in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2013, 03:34 PM
  2. Appropriate formulas for a trivia database
    By eddiesummers in forum Access Tables & Databases
    Replies: 1
    Last Post: 06-25-2012, 03:14 AM
  3. noob question - prompting for sheet moves
    By harvihovart in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-21-2012, 05:26 AM
  4. Trivia Scoring spreadsheet
    By Zeheeba in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-27-2012, 05:54 PM
  5. Trivia Quiz
    By ratcat in forum The Water Cooler
    Replies: 3
    Last Post: 02-12-2009, 10:02 PM
  6. Trivia
    By ChemistB in forum The Water Cooler
    Replies: 30
    Last Post: 06-16-2008, 06:54 PM
  7. Moving Data Question
    By Skip in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-15-2006, 03:00 PM
  8. Replies: 3
    Last Post: 04-20-2005, 08:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1