GithubHelp home page GithubHelp logo

isabella232 / lights-out Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vigetlabs/lights-out

0.0 0.0 0.0 216 KB

New programming challenge based a game from the 80s

Ruby 72.66% Haskell 15.95% JavaScript 11.39%

lights-out's Introduction

Lights Out

This programming challenge is based on a game from my childhood called Lights Out. From Wikipedia:

The game consists of a 5 by 5 grid of lights. When the game starts, a random number or a stored pattern of these lights is switched on. Pressing any of the lights will toggle it and the adjacent lights. The goal of the puzzle is to switch all the lights off, preferably in as few button presses as possible.

For example:

We'll be using a 3x3 grid instead of 5x5. I've created a program in the project's root, board.rb. It takes two arguments:

  1. An initial board state, expressed as nine ones (for on) and zeroes (for off). The first three characters represent the top row, the middle three the middle row, and the last three the last row. So for example, a board state of 010101011 would represent the following state:

     010
     101
     011
    
  2. A optional series of button presses, expressed as digits 1-9, where 1 corresponds to the top left, 3 to the top right, 9 to the bottom right (like a phone).

So calls to board.rb will look something like this:

> ./board.rb 010111010
010
111
010
> ./board.rb 010111010 7
010
011
100
> ./board.rb 010111010 73
001
010
100
> ./board.rb 010111010 5
000
000
000

The challenge is to create a program in your language or languages of choice called lights_out that takes an initial board state and returns an efficient series of moves to turn all the lights off. For example:

> ./lights_out 0000000000

> ./lights_out 010111010
5
> ./lights_out 110001101
179

To start:

  1. Create a directory based on the name of your implementation language (e.g. languages/C)
  2. Create a simple Rakefile that has, at a minimum, a build task within your language's namespace (e.g. C:build). You should check the environment and fail fast if dependencies aren't met.
  3. Create your implementation and run rake from the project root.

Example Rakefile

namespace :C do
  task :check do
    `which cc`
    raise "Please ensure that you have a valid C compiler" unless $?.success?
  end

  task :build => :check do
    path = File.dirname(__FILE__)
    `cd #{path}; make lights_out`
  end
end

lights-out's People

Contributors

dce 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.