Giter Site home page Giter Site logo

code-golf-hole-3's Introduction

Code Golf: Hole 3

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 Irene is writing a package manager. The package manager is almost complete, but she needs your help with dependency resolution. She wants you to write the algorithm that picks the correct version given a version range.

She gives you all the versions of a single published package through stdin, separated by a single space. She also provides you with a version range as the first parameter. She wants your program to print the correct version that satisfies that range.

$ echo '9.0.0 10.0.0 10.1.0 10.1.1 10.1.2 10.1.3 11.0.0' | node my-solution.js '10.*'
10.1.3
$ echo '0.1.0 0.1.1 0.1.2 1.0.0-rc1 0.1.3 0.1.4 1.0.0-rc2 1.0.0 1.0.1 1.1.0 1.2.0' | python3 my-solution.py '1.0.0-*'
1.0.0
$ echo '1.0.0-alpha.1 1.0.0-alpha 1.0.0-alpha.beta 1.0.0-beta.11 1.0.0-beta 1.0.0-beta.2' | ruby my-solution.rb '1.0.0-*'
1.0.0-beta.11
$ echo '1.0.0 2.0.0 3.0.0-alpha' | dotnet script my-solution.csx -- '*'
2.0.0

Rules

  • The languages are limited to JavaScript (Node.js 6.9), Python3 (3.5), Ruby (2.3), and C# (.NET Core 1.1).
  • Your submission is limited to a single file.
  • The series of versions are is provided through stdin, each separated by a single space.
  • Versions provided aren't necessarily chronological or in order of precedence.
  • Each version conforms to semver
    • The versions will be of the form MAJOR.MINOR.PATCH or MAJOR.MINOR.PATCH-PRERELEASE.
    • MAJOR, MINOR, and PATCH are always whole, positive numbers.
    • PRERELEASE can contain alphanumeric characters. Precedence is determined by semver rules.
  • A single version range is given as the first argument.
  • The version range:
    • Can be an exact version: 1.0.0, 1.0.0-alpha1
    • Can use one * wildcard in any position: 1.0.0-*, 1.0.*, 1.*, *
      • A wildcard in the MAJOR, MINOR, or PATCH position indicate that the highest non-prerelease version within that position should be chosen.
      • A wildcard in the PRERELEASE position indicates that the highest prerelease version should be chosen, unless a matching release version is found.
  • A single version must be printed to stdout, and it must be chosen from one of the input versions.

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-3's People

Contributors

perfectsquircle avatar

Stargazers

Roman avatar  avatar

Watchers

 avatar

Forkers

jakegough

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.