mirror of
https://github.com/correl/elm.git
synced 2024-12-22 11:09:08 +00:00
Changes to exercises after an elm-format
This commit is contained in:
parent
8ead7aabfb
commit
5a8aa5e7de
5 changed files with 42 additions and 13 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue