-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
205 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Roman Numerals | ||
|
||
Write a function to convert from normal numbers to Roman Numerals. | ||
|
||
The Romans were a clever bunch. They conquered most of Europe and ruled | ||
it for hundreds of years. They invented concrete and straight roads and | ||
even bikinis. One thing they never discovered though was the number | ||
zero. This made writing and dating extensive histories of their exploits | ||
slightly more challenging, but the system of numbers they came up with | ||
is still in use today. For example the BBC uses Roman numerals to date | ||
their programmes. | ||
|
||
The Romans wrote numbers using letters - I, V, X, L, C, D, M. (notice | ||
these letters have lots of straight lines and are hence easy to hack | ||
into stone tablets). | ||
|
||
```text | ||
1 => I | ||
10 => X | ||
7 => VII | ||
``` | ||
|
||
There is no need to be able to convert numbers larger than about 3000. | ||
(The Romans themselves didn't tend to go any higher) | ||
|
||
Wikipedia says: Modern Roman numerals ... are written by expressing each | ||
digit separately starting with the left most digit and skipping any | ||
digit with a value of zero. | ||
|
||
To see this in practice, consider the example of 1990. | ||
|
||
In Roman numerals 1990 is MCMXC: | ||
|
||
1000=M | ||
900=CM | ||
90=XC | ||
|
||
2008 is written as MMVIII: | ||
|
||
2000=MM | ||
8=VIII | ||
|
||
See also: http://www.novaroma.org/via_romana/numbers.html | ||
|
||
## Hints | ||
|
||
To complete this exercise you need to implement the function `numerals`, | ||
that *maybe* converts a number to a *string* representing a roman numeral. | ||
|
||
Your function is expected to, at least, convert numbers up to 3000, | ||
but is up to you to decide how far you want to go. | ||
|
||
|
||
|
||
## Getting Started | ||
|
||
For installation and learning resources, refer to the | ||
[exercism help page](http://exercism.io/languages/haskell). | ||
|
||
## Running the tests | ||
|
||
To run the test suite, execute the following command: | ||
|
||
```bash | ||
stack test | ||
``` | ||
|
||
#### If you get an error message like this... | ||
|
||
``` | ||
No .cabal file found in directory | ||
``` | ||
|
||
You are probably running an old stack version and need | ||
to upgrade it. | ||
|
||
#### Otherwise, if you get an error message like this... | ||
|
||
``` | ||
No compiler found, expected minor version match with... | ||
Try running "stack setup" to install the correct GHC... | ||
``` | ||
|
||
Just do as it says and it will download and install | ||
the correct compiler version: | ||
|
||
```bash | ||
stack setup | ||
``` | ||
|
||
## Running *GHCi* | ||
|
||
If you want to play with your solution in GHCi, just run the command: | ||
|
||
```bash | ||
stack ghci | ||
``` | ||
|
||
## Feedback, Issues, Pull Requests | ||
|
||
The [exercism/haskell](https://github.com/exercism/haskell) repository on | ||
GitHub is the home for all of the Haskell exercises. | ||
|
||
If you have feedback about an exercise, or want to help implementing a new | ||
one, head over there and create an issue. We'll do our best to help you! | ||
|
||
## Source | ||
|
||
The Roman Numeral Kata [http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals](http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals) | ||
|
||
## Submitting Incomplete Solutions | ||
It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: roman-numerals | ||
version: 1.2.0.5 | ||
|
||
dependencies: | ||
- base | ||
|
||
library: | ||
exposed-modules: Roman | ||
source-dirs: src | ||
# dependencies: | ||
# - foo # List here the packages you | ||
# - bar # want to use in your solution. | ||
|
||
tests: | ||
test: | ||
main: Tests.hs | ||
source-dirs: test | ||
dependencies: | ||
- roman-numerals | ||
- hspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Roman (numerals) where | ||
|
||
numerals :: Integer -> Maybe String | ||
numerals n = error "You need to implement this function." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
resolver: lts-11.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
{-# OPTIONS_GHC -fno-warn-type-defaults #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
import Data.Foldable (for_) | ||
import Test.Hspec (Spec, describe, it, shouldBe) | ||
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith) | ||
|
||
import Roman (numerals) | ||
|
||
main :: IO () | ||
main = hspecWith defaultConfig {configFastFail = True} specs | ||
|
||
specs :: Spec | ||
specs = describe "numerals" $ for_ cases test | ||
where | ||
|
||
test Case{..} = it explanation assertion | ||
where | ||
explanation = show number ++ ": " ++ description | ||
assertion = numerals (fromIntegral number) `shouldBe` expected | ||
|
||
data Case = Case { description :: String | ||
, number :: Integer | ||
, expected :: Maybe String | ||
} | ||
|
||
cases :: [Case] | ||
cases = [ Case { description = "1 is a single I" | ||
, number = 1 | ||
, expected = Just "I" | ||
} | ||
, Case { description = "2 is two I's" | ||
, number = 2 | ||
, expected = Just "II" | ||
} | ||
, Case { description = "3 is three I's" | ||
, number = 3 | ||
, expected = Just "III" | ||
} | ||
, Case { description = "4, being 5 - 1, is IV" | ||
, number = 4 | ||
, expected = Just "IV" | ||
} | ||
, Case { description = "5 is a single V" | ||
, number = 5 | ||
, expected = Just "V" | ||
} | ||
, Case { description = "6, being 5 + 1, is VI" | ||
, number = 6 | ||
, expected = Just "VI" | ||
} | ||
, Case { description = "9, being 10 - 1, is IX" | ||
, number = 9 | ||
, expected = Just "IX" | ||
} | ||
, Case { description = "20 is two X's" | ||
, number = 27 | ||
, expected = Just "XXVII" | ||
} | ||
, Case { description = "48 is not 50 - 2 but rather 40 + 8" | ||
, number = 48 | ||
, expected = Just "XLVIII" | ||
} | ||
, Case { description = "49 is not 40 + 5 + 4 but rather 50 - 10 + 10 - 1" | ||
, number = 49 | ||
, expected = Just "XLIX" | ||
} | ||
, Case { description = "50 is a single L" | ||
, number = 59 | ||
, expected = Just "LIX" | ||
} | ||
, Case { description = "90, being 100 - 10, is XC" | ||
, number = 93 | ||
, expected = Just "XCIII" | ||
} | ||
, Case { description = "100 is a single C" | ||
, number = 141 | ||
, expected = Just "CXLI" | ||
} | ||
, Case { description = "60, being 50 + 10, is LX" | ||
, number = 163 | ||
, expected = Just "CLXIII" | ||
} | ||
, Case { description = "400, being 500 - 100, is CD" | ||
, number = 402 | ||
, expected = Just "CDII" | ||
} | ||
, Case { description = "500 is a single D" | ||
, number = 575 | ||
, expected = Just "DLXXV" | ||
} | ||
, Case { description = "900, being 1000 - 100, is CM" | ||
, number = 911 | ||
, expected = Just "CMXI" | ||
} | ||
, Case { description = "1000 is a single M" | ||
, number = 1024 | ||
, expected = Just "MXXIV" | ||
} | ||
, Case { description = "3000 is three M's" | ||
, number = 3000 | ||
, expected = Just "MMM" | ||
} | ||
] |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.