Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main exposing (main)
- import Html exposing (Html, div, h1, text, textarea)
- import Html.Attributes exposing (class, readonly, rows, style, value)
- import Html.Events exposing (onInput)
- -- Fibonacci stuff
- fibonacciFy : String -> String -> String
- fibonacciFy origIndent input =
- input
- |> String.lines
- |> List.map (fibonacciFyLine origIndent)
- |> String.join "\n"
- fibonacciFyLine : String -> String -> String
- fibonacciFyLine origIndent input =
- let
- trimed =
- String.trimLeft input
- indentLevel =
- (String.length input - String.length trimed) // String.length origIndent
- in
- String.repeat (cumulativeFib indentLevel) " " ++ trimed
- cumulativeFib : Int -> Int
- cumulativeFib n =
- List.range 0 n
- |> List.map fibonacci
- |> List.sum
- fibonacci : Int -> Int
- fibonacci n =
- let
- fib a b n =
- if n <= 0 then
- a
- else
- fib b (a + b) (n - 1)
- in
- fib 0 1 n
- --
- type Msg
- = SetInput String
- | SetOrigIndent String
- update msg model =
- case msg of
- SetInput input ->
- { model | input = input }
- SetOrigIndent ind ->
- { model | origIndent = ind }
- view { input, origIndent } =
- div []
- [ div []
- [ text "Original indent:"
- , Html.input [ onInput SetOrigIndent, value origIndent ] []
- ]
- , div []
- [ h1 [] [ text "Original" ]
- , inputTxt [ onInput SetInput ] input
- ]
- , div []
- [ h1 [] [ text "Fibonaccified" ]
- , inputTxt [ readonly True ] (fibonacciFy origIndent input)
- ]
- ]
- main =
- Html.beginnerProgram
- { model = { origIndent = " ", input = sample }
- , update = update
- , view = view
- }
- --
- inputTxt attrs txt =
- textarea ([ value txt, class "txtInput", rows 17 ] ++ attrs) []
- sample =
- """foo {
- bar {
- baz {
- quz {
- quux {
- corge {
- grault {
- garply {
- // waldoo
- }
- }
- }
- }
- }
- }
- }
- }"""
Advertisement
Add Comment
Please, Sign In to add comment