GithubHelp home page GithubHelp logo

fizzbuzz's Introduction

Metrics

fizzbuzz's People

Contributors

estog avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

fossabot

fizzbuzz's Issues

Create classic FizzBuzz solution

The problem description is the following (adapted from https://wiki.c2.com/?FizzBuzzTest):

"Write a program that generates the numbers from 1 to n. But for
multiples of three gives “Fizz” instead of the number and for the
multiples of five gives “Buzz”. For numbers which are multiples of both
three and five gives “FizzBuzz”."

For example:

>>> list(classic_fizzbuzz(20))
['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz', '16', '17', 'Fizz', '19', 'Buzz']

Make a general parametrized version of FizzBuzz.

This version must allow to specify a set of conditions with its respective replacements functions and a common transformation to be applied to each resultant replacement in a way that each final replacement will expose a common trait.

For example:

>>> mod3 = lambda e: e % 3 == 0
>>> mod5 = lambda e: e % 5 == 0
>>> mapping={mod3: lambda e: 'Fizz', mod5: lambda e: 'Buzz'}
>>> fusion = lambda ac, r: ac+r
>>> assert list(classic_fizzbuzz(100)) == \
            list(general_fizzbuzz(iterable=range(1, 101), mapping=mapping,
...                              default=str, fusion=fusion, common=lambda r: r))

>>> assert classic_fizzbuzz_as_text(100, ', ') == \
            ''.join( general_fizzbuzz( iterable=range(1, 101),
...                                   mapping=mapping,
...                                   default=str, fusion=fusion,
...                                   common=lambda r: f'{r}, '   ) )

>>> list(  general_fizzbuzz(  iterable=range(55, 61),
...                           mapping={ mod3: lambda e: 'Fuzzy',
...                                     mod5: lambda e: 'Buzzy'  },
...                           default=lambda x: 'Normal',
...                           fusion=fusion,
...                           common=lambda r: f'({r})'              )  )
['(Buzzy)', '(Normal)', '(Fuzzy)', '(Normal)', '(Normal)', '(FuzzyBuzzy)']

>>> list(  general_fizzbuzz(  iterable=range(55, 61),
...                           mapping={ mod3: lambda e: (e, 'Fuzzy'),
...                                     mod5: lambda e: (e, 'Buzzy')  },
...                           default=lambda x: 'Normal',
...                           fusion=lambda ac, r: (ac[0], ac[1]+r[1]),
...                           common=lambda r: r                          )  )
[(55, 'Buzzy'), 'Normal', (57, 'Fuzzy'), 'Normal', 'Normal', (60, 'FuzzyBuzzy')]

Add web services

Create two services. The first gives the classic FizzBuzz result in the body of a sole response. The other gives the result as a stream. The services must have two parameters: n is the maximum number in the sequence, sep is the separator used to separate each member of the resulting sequence. Keep the trailing sep at the end of the resulting sequence. For example:

$> curl -X GET "http://${SERVER}/classic-fizzbuzz/?n=10&sep=, "
1,2,Fizz,4,Buzz,Fizz,7,8,Fizz,Buzz,

where $SERVER is the server dir.

Add CLI

Add CLI to run features from console

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.