Created
May 1, 2016 10:47
-
-
Save kgashok/523d3ab01382cc3a53f320582ae81b04 to your computer and use it in GitHub Desktop.
Code for Bracket Validator in Elm
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
module Validator where | |
-- import Html exposing (..) | |
import Text exposing (..) | |
import Graphics.Element exposing (..) | |
import Color exposing (..) | |
import SStack as Stack exposing (..) | |
reverseString : String -> String | |
reverseString str = | |
Stack.reverse str | |
invalidString: String | |
invalidString = | |
"(()))" | |
validString: String | |
validString = | |
"(())" | |
validateString: String -> Bool | |
validateString s = | |
validate s Stack.empty | |
resultString : String -> Element | |
resultString s = | |
s ++ " is " ++ toString (validateString s) | |
|> Text.fromString | |
|> Text.color Color.blue | |
-- |> Text.bold | |
|> Text.height 60 | |
|> centered | |
testExpressions: List String | |
testExpressions = | |
[ | |
invalidString, | |
validString, | |
"()()()()", -- valid | |
"() (()) (((())))", -- valid | |
"(((0))" -- not valid | |
] | |
main : Element | |
main = | |
-- (reverseString "Hello World !") ++ " " ++ | |
{- List.map (\s -> resultString s) testExpressions | |
|> Text.concat | |
|> Html.text | |
-} | |
flow down (List.map resultString testExpressions ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment