Code Monkey home page Code Monkey logo

c-skysrcaper-puzzle's Introduction

Skyscraper Puzzle Solver

license GitHub top language

This is a solver for the Skyscraper Puzzle, which is a logic puzzle that involves a grid of buildings with varying heights. The objective of the puzzle is to determine the heights of the buildings in each row and column, based on the clues given on the edges of the grid.

Puzzle Rules

The rules of the puzzle are as follows:

  • The grid is a square with a size of N x N.
  • Each cell in the grid represents a building, and its value represents the height of the building.
  • The buildings in each row and column must have different heights.
  • The clues on the edges of the grid indicate how many buildings can be seen from that direction. A building can be seen if its height is greater than the heights of the buildings in front of it in that direction.

Usage

To use this solver, follow these steps:

  1. Run gcc -Wall -Wextra -Werror main.c grid.c print.c solve.c valid.c -o skyscraper in terminal.
  2. Run ./skyscraper 'UpFirst UpSecond UpThird UpFourth DownFirst DownSecond DownThird DownFourth LeftFirst LeftSecond LeftThird LeftFourth RightFirst RightSecond RightThird RightFourth'
  3. Enjoy!

Algorithm

This solver uses a backtracking algorithm to find the solution to the puzzle. The algorithm works by iterating through each cell in the grid, and attempting to fill it with a valid value. If there are no valid values for a cell, the algorithm backtracks to the previous cell and tries a different value.

Note

The current solver only supports 4x4 grid. For NxN grid, dynamic programming approach is not implemented yet.

c-skysrcaper-puzzle's People

Contributors

leesinliang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.