Skip to content

A simple code challenge with tricky requirements :) (more on readme)

Notifications You must be signed in to change notification settings

gabfr/linian-number-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linian Number Analyzer Code Challenge

We have to write a program that prints all the numbers from 1 to 100. However, for multiples of 3, instead of the number, print "Linio". For multiples of 5 print "IT". For numbers which are multiples of both 3 and 5, print "Linianos".

But here's the catch: you can use only one if. No multiple branches, ternary operators or else.

Requirements

  • 1 if
  • You can't use else, else if or ternary
  • Unit tests
  • Feel free to apply your SOLID knowledge
  • You can write the challenge in any language you want. Here at Linio we are big fans of PHP, Kotlin and TypeScript

Solution

The solution purpose is to implement the described rules above with pre-defined analyzers.

This way we can concentrate each analysis in a self-contained class with a common contract with other analyzers.

This contract is made to receive an integer and return a simple string with the analysis result.

In case the analyzer is not the right one for the number, the Analyzer will return null and the AnalysisManager will try to run the next Analyzers until he finds one that returns the analysis result. For that reason we will have a Fallback analyzer called DecimalFallbackAnalyzer.

Getting started

Before running the analyzer, you will need to install the project dependencies with composer install.

Running the Analyzer

By default the analyzer will run in the range from 1 to 100, you can run it with this simple command:

bin/linian-number-analyzer

If you receive the permission error, try adding execution permission for this binary file:

chmod +x bin/linian-number-analyzer

Running the tests

To run the test cases within this project just execute:

vendor/bin/phpunit tests/AnalyzersTests.php

About

A simple code challenge with tricky requirements :) (more on readme)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages