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 7804849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:03:14+00:00 2026-06-02T02:03:14+00:00

I’m programming a Killer Sudoku Solver in Ruby and I try to take human

  • 0

I’m programming a Killer Sudoku Solver in Ruby and I try to take human strategies and put them into code. I have implemented about 10 strategies but I have a problem on this one.

In killer sudoku, we have “zones” of cells and we know the sum of these cells and we know possibilities for each cell.

Example :

  • Cell 1 can be 1, 3, 4 or 9
  • Cell 2 can be 2, 4 or 5
  • Cell 3 can be 3, 4 or 9
  • The sum of all cells must be 12

I want my program to try all possibilities to eliminate possibilities. For instance, here, cell 1 can’t be 9 because you can’t make 3 by adding two numbers possible in cells 2 and 3.

So I want that for any number of cells, it removes the ones that are impossible by trying them and seeing it doesn’t work.

How can I get this working ?

  • 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-06-02T02:03:15+00:00Added an answer on June 2, 2026 at 2:03 am

    There’s multiple ways to approach the general problem of game solving, and emulating human strategies is not always the best way. That said, here’s how you can solve your question:

    1st way, brute-forcy

    Basically, we want to try all possibilities of the combinations of the cells, and pick the ones that have the correct sum.

    cell_1 = [1,3,4,9]
    cell_2 = [2,4,5]
    cell_3 = [3,4,9]
    all_valid_combinations = cell_1.product(cell_2,cell_3).select {|combo| combo.sum == 12}
    # => [[1, 2, 9], [3, 5, 4], [4, 4, 4], [4, 5, 3]]
    #.sum isn't a built-in function, it's just used here for convenience
    

    to pare this down to individual cells, you could do:

    cell_1 = all_valid_combinations.map {|combo| combo[0]}.uniq
    # => [1, 3, 4]
    cell_2 = all_valid_combinations.map {|combo| combo[1]}.uniq
    # => [2, 5, 4]
    . . .
    

    if you don’t have a huge large set of cells, this way is easier to code. it can get a bit inefficienct though. For small problems, this is the way I’d use.


    2nd way, backtracking search

    Another well known technique takes the problem from the other approach. Basically, for each cell, ask “Can this cell be this number, given the other cells?”

    so, starting with cell 1, can the number be 1? to check, we see if cells 2 and 3 can sum to 11. (12-1)
    * can cell 2 have the value 2? to check, can cell 3 sum to 9 (11-1)

    and so on. In very large cases, where you could have many many valid combinations, this will be slightly faster, as you can return ‘true’ on the first time you find a valid number for a cell. Some people find recursive algorithms a bit harder to grok, though, so your mileage may vary.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to loop through a bunch of documents I have to put
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't

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.