estog / fizzbuzz Goto Github PK
View Code? Open in Web Editor NEWFizzBuzz brainstorm!
License: MIT License
FizzBuzz brainstorm!
License: MIT License
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.
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']
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 CLI to run features from console
Add options to use the web services from the CLI.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.