Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 960863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:14:50+00:00 2026-05-16T01:14:50+00:00

found this puzzle HERE … I made a brute force solution and I would

  • 0

found this puzzle HERE… I made a brute force solution and I would like to know how you woul solve it…

Buzz, Woody, Rex, and Hamm have to escape from Zurg(a) They merely have to cross
one last bridge before they are free. However, the bridge is fragile and can hold at most
two of them at the same time. Moreover, to cross the bridge a flashlight is needed to
avoid traps and broken parts. The problem is that our friends have only one flashlight
with one battery that lasts for only 60 minutes (this is not a typo: sixty). The toys need
different times to cross the bridge (in either direction):

 TOY     TIME
Buzz   5 minutes
Woody 10 minutes
Rex   20 minutes
Hamm  25 minutes

Since there can be only two toys on the bridge at the same time, they cannot cross the
bridge all at once. Since they need the flashlight to cross the bridge, whenever two have
crossed the bridge, somebody has to go back and bring the flashlight to those toys on
the other side that still have to cross the bridge.
The problem now is: In which order can the four toys cross the bridge in time (that
is, in 60 minutes) to be saved from Zurg?

//(a) These are characters from the animation movie “Toy Story 2”.

here is my solution:

public Form1()
{
    InitializeComponent();
    List<toy> toys = new List<toy>(){
        new toy { name = "buzz", time = 5 } ,
        new toy { name = "woody", time = 10 } ,
        new toy { name = "rex", time = 20 } ,
        new toy { name = "ham", time = 25 } ,
        };
    var posibles = Combinaciones(toys, 4).ToList(); //all permutations
    List<Tuple<string, int>> solutions = new List<Tuple<string, int>>();

    foreach (var pointA in posibles)
    {
        string order = "";
        int flashlight = 60;
        List<toy> pointB = new List<toy>();
        do
        {
            var fastestInA = pointA.Take(2).ToList();
            flashlight -= fastestInA.Max(t => t.time);
            order += "go " + String.Join(",", fastestInA.Select(t => t.name)) + "\n";
            fastestInA.ForEach(t => pointA.Remove(t));
            pointB.AddRange(fastestInA);
            if (pointB.Count < 4)
            {
                var fastestInB = pointB.Take(1).ToList();
                flashlight -= fastestInB.Max(t => t.time);
                order += "return " + String.Join(",", fastestInB.Select(t => t.name).ToArray()) + "\n";
                fastestInB.ForEach(t => pointB.Remove(t));
                pointA.AddRange(fastestInB);
            }
        } while (pointB.Count != 4);

        solutions.Add(new Tuple<string, int>(order, flashlight));
    }

    var optimal = solutions.Where(s => s.Item2 == solutions.Max(t => t.Item2)).ToList();
    optimal.ForEach(s => Console.Write("Order:\n" + s.Item1 + "TimeLeft:" + s.Item2 + "\n\n"));
}

public class toy
{
    public int time { get; set; }
    public string name { get; set; }
}

// this is to do permutations
public static List<List<toy>> Combinaciones(List<toy> list, int take)
{
    List<List<toy>> combs = new List<List<toy>>();
    foreach (var item in list)
    {
        var newlist = list.Where(i => !i.Equals(item)).ToList();
        var returnlist = take <= 1 ? new List<List<toy>> { new List<toy>() } : Combinaciones(newlist, take - 1);
        foreach (var l in returnlist)
        {
            l.Add(item);
        }
        combs.AddRange(returnlist);
    }

    return combs.ToList();
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:14:50+00:00Added an answer on May 16, 2026 at 1:14 am

    Recursive solution using LINQ:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace Zurg
    {
      class Program
      {
        static readonly Toy[] toys = new Toy[]{
            new Toy("Buzz", 5),
            new Toy("Woody", 10),
            new Toy("Rex", 20),
            new Toy("Ham", 25),
            };
        static readonly int totalTorch = 60;
    
        static void Main()
        {
          Console.WriteLine(Go(new State(toys, new Toy[0], totalTorch, "")).Message);
        }
    
        static State Go(State original)
        {
          var final = (from first in original.Start
                       from second in original.Start
                       where first != second
                       let pair = new Toy[]
                       {
                         first,
                         second
                       }
                       let flashlight = original.Flashlight - pair.Max(t => t.Time)
                       select Return(new State(
                         original.Start.Except(pair),
                         original.Finish.Concat(pair),
                         flashlight,
                         original.Message + string.Format(
                          "Go {0}. {1} min remaining.\n",
                          string.Join(", ", pair.Select(t => t.Name)),
                          flashlight)))
                       ).Aggregate((oldmax, cur) => cur.Flashlight > oldmax.Flashlight ? cur : oldmax);
    
          return final;
        }
    
        static State Return(State original)
        {
          if (!original.Start.Any())
            return original;
    
          var final = (from toy in original.Finish
                       let flashlight = original.Flashlight - toy.Time
                       let toyColl = new Toy[] { toy }
                       select Go(new State(
                         original.Start.Concat(toyColl),
                         original.Finish.Except(toyColl),
                         flashlight,
                         original.Message + string.Format(
                          "Return {0}. {1} min remaining.\n",
                          toy.Name,
                          flashlight)))
                       ).Aggregate((oldmax, cur) => cur.Flashlight > oldmax.Flashlight ? cur : oldmax);
    
          return final;
        }
      }
    
      public class Toy
      {
        public string Name { get; set; }
        public int Time { get; set; }
        public Toy(string name, int time)
        {
          Name = name;
          Time = time;
        }
      }
    
      public class State
      {
        public Toy[] Start { get; private set; }
        public Toy[] Finish { get; private set; }
        public int Flashlight { get; private set; }
        public string Message { get; private set; }
        public State(IEnumerable<Toy> start, IEnumerable<Toy> finish, int flashlight, string message)
        {
          Start = start.ToArray();
          Finish = finish.ToArray();
          Flashlight = flashlight;
          Message = message;
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more of a puzzle than anything. I've actually found a solution but
I was trying to solve ITA Software's Word Nubmers puzzle using a brute force
I am trying to solve the Spotify Puzzle 'Bilateral' found here: http://www.spotify.com/us/jobs/tech/bilateral-projects/ I have
Found this while reading the Neo4j manual, specifically here , I found the sentence:
Found this Multimap containing pairs? , but it is not much help How would
I have this funny issue. I know this error message is found in a
I'm using Java to solve the 8-Puzzle problem using DFS. this is what I
Found this puzzle inside an image. According to my thinking the total number of
I found this puzzle in a C aptitude paper. void change() { //write something
I'm trying to solve the best before Spotify puzzle described on this page .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.