Skip to content

Instantly share code, notes, and snippets.

@Judgy53
Last active July 23, 2018 02:38
Show Gist options
  • Save Judgy53/b754110949d949acc1ae48fed566a306 to your computer and use it in GitHub Desktop.
Save Judgy53/b754110949d949acc1ae48fed566a306 to your computer and use it in GitHub Desktop.
ch2 plan url encode idea
nodesToBuild : G.Graph -> Set G.NodeId -> Maybe String
nodesToBuild graph =
Set.toList
>> List.sort
>> splitforAlphabet []
>> alphabetize
>> String.join "&"
>> (\s ->
if s == "" then
Nothing
else
Just s
)
splitforAlphabet : List (List G.NodeId) -> List G.NodeId -> List (List G.NodeId)
splitforAlphabet globalList currentList =
let
( stList, bgeList ) =
List.Extra.break ((<=) 74) currentList
shiftedBgeList =
List.map (\i -> i - 73) bgeList
in
if not (List.isEmpty shiftedBgeList) then
splitforAlphabet (globalList ++ [ stList ]) shiftedBgeList
else
globalList ++ [ stList ]
alphabetize : List (List G.NodeId) -> List String
alphabetize splittedList =
let
alphabet =
String.toList "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$-_.+!*'(),"
result =
List.map
(\l ->
String.fromList <|
List.map
(\i ->
List.Extra.getAt (i - 1) alphabet
|> Maybe.withDefault '1'
)
l
)
splittedList
in
result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment