Skip to content

Instantly share code, notes, and snippets.

@kgashok
Created May 1, 2016 10:47
Show Gist options
  • Save kgashok/523d3ab01382cc3a53f320582ae81b04 to your computer and use it in GitHub Desktop.
Save kgashok/523d3ab01382cc3a53f320582ae81b04 to your computer and use it in GitHub Desktop.
Code for Bracket Validator in Elm
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