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

  • Home
  • SEARCH
  • 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 60581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:11:04+00:00 2026-05-10T18:11:04+00:00

I’m practicing for the upcoming ACM programming competition in a week and I’ve gotten

  • 0

I’m practicing for the upcoming ACM programming competition in a week and I’ve gotten stumped on this programming problem.

The problem is as follows:


You have a puzzle consisting of a square grid of size 4. Each grid square holds a single coin; each coin is showing either heads (H) and tails (T). One such puzzle is shown here:

H H H H
T T T T
H T H T
T T H T

Any coin that is current showing Tails (T) can be flipped to Heads (H). However, any time we flip a coin, we must also flip the adjacent coins direct above, below and to the left and right in the same row. Thus if we flip the second coin in the second row we must also flip 4 other coins, giving us this arrangment (coins that changed are shown in bold).

H T H H
H H H T
H H H T
T T H T

If a coin is at the edge of the puzzle, so there is no coin on one side or the other, then we flip fewer coins. We do not ‘wrap around’ to the other side. For example, if we flipped the bottom right coin of the arragnement above we would get:

H T H H
H H H T
H H H H
T T T H

Note: Only coins showing (T) tails can be selected for flipping. However, anytime we flip such a coin, adjacent coins are also flipped, regardless of their state.

The goal of the puzzle is to have all coins show heads. While it is possible for some arragnements to not have solutions, all the problems given will have solutions. The answer we are looking for is, for any given 4×4 grid of coins what is the least number of flips in order to make the grid entirely heads.

For Example the grid:
H T H H
T T T H
H T H T
H H T T

The answer to this grid is: 2 flips.


What I have done so far:

I’m storing our grids as two-dimensional array of booleans. Heads = true, tails = false. I have a flip(int row, int col) method that will flip the adjacent coins according the rules above and I have a isSolved() method that will determine if the puzzle is in a solved state (all heads). So we have our ‘mechanics’ in place.

The part we are having problems with is how should we loop through, going an the least amount of times deep?

  • 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. 2026-05-10T18:11:04+00:00Added an answer on May 10, 2026 at 6:11 pm

    Your puzzle is a classic Breadth-First Search candidate. This is because you’re looking for a solution with the fewest possible ‘moves’.

    If you knew the number of moves to the goal, then that would be ideal for a Depth-First Search.

    Those Wikipedia articles contain plenty of information about the way the searches work, they even contain code samples in several languages.

    Either search can be recursive, if you’re sure you won’t run out of stack space.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 113k
  • Answers 113k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SQLITE_DONE http://www.sqlite.org/c3ref/step.html You could also try printing out the error… May 11, 2026 at 10:05 pm
  • Editorial Team
    Editorial Team added an answer No, it's not inefficient to create lots of SqlConnection objects… May 11, 2026 at 10:05 pm
  • Editorial Team
    Editorial Team added an answer Implement the System.Web.SessionState.IRequiresSessionState interface public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState… May 11, 2026 at 10:05 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.