Skip to content

Instantly share code, notes, and snippets.

@pablen
Created December 4, 2017 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablen/9ea3b41d9bfdabfa1c96313a4c989117 to your computer and use it in GitHub Desktop.
Save pablen/9ea3b41d9bfdabfa1c96313a4c989117 to your computer and use it in GitHub Desktop.
Advent of Code. Day 4. Part 2.
module Main exposing (..)
import Html exposing (text)
import Set
input : String
input =
"""pphsv ojtou brvhsj cer ntfhlra udeh ccgtyzc zoyzmh jum lugbnk
{-- more lines... --}
"""
isValidPassPhrase : String -> Bool
isValidPassPhrase line =
let
wordsCount =
line
|> String.words
|> List.length
filteredCount =
line
|> String.words
|> List.map (String.toList >> List.sort >> String.fromList)
|> Set.fromList
|> Set.size
in
wordsCount == filteredCount
main : Html.Html msg
main =
input
|> String.lines
|> List.filter isValidPassPhrase
|> List.length
|> toString
|> text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment