Changes to exercises after an elm-format

This commit is contained in:
Lew Parker 2016-03-19 12:43:27 -06:00
parent 8ead7aabfb
commit 5a8aa5e7de
5 changed files with 42 additions and 13 deletions

View file

@ -6,8 +6,11 @@ import String exposing (toLower, toList)
detect : String -> List String -> List String detect : String -> List String -> List String
detect word candidates = detect word candidates =
let let
original = toLower word original =
ref = normalize word toLower word
ref =
normalize word
in in
List.filter (\w -> normalize w == ref && toLower w /= original) candidates List.filter (\w -> normalize w == ref && toLower w /= original) candidates

View file

@ -4,7 +4,8 @@ module DifferenceOfSquares (..) where
squareOfSum : Int -> Int squareOfSum : Int -> Int
squareOfSum n = squareOfSum n =
let let
sum = n * (n + 1) // 2 sum =
n * (n + 1) // 2
in in
sum * sum sum * sum

View file

@ -1,4 +1,4 @@
module Raindrops where module Raindrops (..) where
import String import String
@ -7,10 +7,20 @@ raindrops : Int -> String
raindrops number = raindrops number =
let let
drops = drops =
[ if number % 3 == 0 then "Pling" else "" [ if number % 3 == 0 then
, if number % 5 == 0 then "Plang" else "" "Pling"
, if number % 7 == 0 then "Plong" else "" else
""
, if number % 5 == 0 then
"Plang"
else
""
, if number % 7 == 0 then
"Plong"
else
""
] ]
result = result =
String.join "" drops String.join "" drops
in in

View file

@ -13,16 +13,29 @@ toRNA dna =
|> Result.map (String.join "") |> Result.map (String.join "")
-- Copied from elm-result-extra -- Copied from elm-result-extra
resultExtraCombine : List (Result x a) -> Result x (List a) resultExtraCombine : List (Result x a) -> Result x (List a)
resultExtraCombine = List.foldr (Result.map2 (::)) (Ok []) resultExtraCombine =
List.foldr (Result.map2 (::)) (Ok [])
toRNANucleotide : Char -> Result Char Char toRNANucleotide : Char -> Result Char Char
toRNANucleotide nuc = toRNANucleotide nuc =
case nuc of case nuc of
'C' -> Ok 'G' 'C' ->
'G' -> Ok 'C' Ok 'G'
'A' -> Ok 'U'
'T' -> Ok 'A' 'G' ->
_ -> Err nuc Ok 'C'
'A' ->
Ok 'U'
'T' ->
Ok 'A'
_ ->
Err nuc

View file

@ -5,11 +5,13 @@ import List exposing (head, tail)
import Maybe exposing (withDefault) import Maybe exposing (withDefault)
import Regex import Regex
{- {-
To the unaware: this was written by a very green elmer, so don't consider To the unaware: this was written by a very green elmer, so don't consider
it an idiomatic exemplar to emulate. it an idiomatic exemplar to emulate.
-} -}
encode : String -> String encode : String -> String
encode string = encode string =
String.toList string String.toList string