Giter Site home page Giter Site logo

code-golf-hole-4's Introduction

Code Golf: Hole 4

Introduction

Code Golf is a competition where given a programming prompt, the shortest source code (measured in bytes) to fully implement the prompt wins the challenge. Ties are broken by the first golfer to submit a solution of a given size.

Challenge

Your friend Jake is writing a Connect Four clone. The game is almost complete, but he needs your help with the computer opponent. He wants you to write a program that picks the winning move, and he wants it to be small and fast!

He gives you the state of the game board through stdin. He also provides you the next disc (o or x) as the first argument. He wants your program to print the column where dropping the next disc will win the game.

$ cat games/game-01.txt | node my-solution.js 'o'
5
$ cat games/game-02.txt | python3 my-solution.py 'o'
2
$ cat games/game-03.txt | ruby my-solution.rb 'x'
2
$ cat games/game-04.txt | dotnet script my-solution.csx -- 'o'
5

Rules

  • The languages are limited to JavaScript (Node.js 6.9), Python3 (3.6), Ruby (2.4), and C# (.NET Core 1.1).
  • Your submission is limited to a single file.
  • The game board is provided through stdin, one row per line.
    • The game board is 7 columns wide and 6 rows tall
    • The board has 4 valid characters:
      • . is an empty cell
      • x is a red disc
      • o is a blue disc
      • \n is a new row
  • The next disc is provided as the first argument, x for a red disc, o for a blue disc.
  • Your program must print a single number
    • The number equals the column where dropping a disc results in a winning move.
    • The columns are indexed 1-7 from left to right.
    • A winning move results in 4 of the same color disc in a vertical, horizontal, or diagonal line.

Scoring

Please submit a single file (.js, .py, .rb, or .csx). The included node script code-golf.sh will be used to score your file. To run this script, you must have Node.js installed.

macOS

$ ./code-golf.sh my-solution.js
Your score is 456

Windows

C:\> node code-golf.sh my-solution.js
Your score is 456

Docker

$ docker build -t golf .
$ docker run -it -v "$PWD":/tmp/src golf bash
$ ./code-golf.sh my-solution.js
Your score is 456

golf

code-golf-hole-4's People

Contributors

perfectsquircle avatar

Stargazers

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