Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Angelov, Georgi
cryptic-solver-haskell
Commits
83dbc9c2
Commit
83dbc9c2
authored
Oct 25, 2021
by
Georgi Angelov
Browse files
Refactored helper functions into Utils.hs
parent
7d5cd2f4
Changes
2
Show whitespace changes
Inline
Side-by-side
Server.hs
View file @
83dbc9c2
import
Happstack.Server
import
Solver
import
Utils
import
Control.Monad
(
msum
)
my
Conf
=
Conf
server
Conf
=
Conf
{
port
=
5001
,
validator
=
Nothing
,
logAccess
=
Just
logMAccess
...
...
@@ -11,7 +11,7 @@ myConf = Conf
,
threadGroup
=
threadGroup
nullConf
}
main
=
simpleHTTP
my
Conf
$
msum
[
dir
"solve"
$
path
$
\
clue
->
path
$
\
wordLength
main
=
simpleHTTP
server
Conf
$
msum
[
dir
"solve"
$
path
$
\
clue
->
path
$
\
wordLength
->
ok
$
show
(
solveReturn
(
clue
,
wordLength
))
,
dir
"solveAll"
$
path
$
\
clue
->
path
$
\
wordLength
->
ok
$
show
(
solveAllReturn
(
clue
,
wordLength
))
...
...
@@ -20,19 +20,3 @@ main = simpleHTTP myConf $ msum [ dir "solve" $ path $ \clue -> path $ \wordLeng
,
dir
"solveWithAnswers"
$
path
$
\
clue
->
path
$
\
wordLength
->
path
$
\
answers
->
ok
$
show
(
solveAnswers
clue
wordLength
answers
)
]
solveAnswers
clue
wordLength
answers
=
solveEach
clue
wordLength
(
wordsWhen
(
==
','
)
answers
)
where
solveEach
_
_
[]
=
[]
solveEach
clue
wordLength
(
a
:
as
)
|
null
(
solveWithAnswerReturn
(
clue
,
wordLength
)
a
)
=
solveEach
clue
wordLength
as
|
otherwise
=
head
(
solveWithAnswerReturn
(
clue
,
wordLength
)
a
)
:
solveEach
clue
wordLength
as
wordsWhen
::
(
Char
->
Bool
)
->
String
->
[
String
]
wordsWhen
p
s
=
case
dropWhile
p
s
of
""
->
[]
s'
->
w
:
wordsWhen
p
s''
where
(
w
,
s''
)
=
break
p
s'
Utils.hs
0 → 100644
View file @
83dbc9c2
import
Solver
-- Receives a list of possible answers to a clue and returns a list of all valid answers
solveAnswers
clue
wordLength
answers
=
solveEach
clue
wordLength
(
wordsWhen
(
==
','
)
answers
)
where
solveEach
_
_
[]
=
[]
solveEach
clue
wordLength
(
a
:
as
)
|
null
(
solveWithAnswerReturn
(
clue
,
wordLength
)
a
)
=
solveEach
clue
wordLength
as
|
otherwise
=
head
(
solveWithAnswerReturn
(
clue
,
wordLength
)
a
)
:
solveEach
clue
wordLength
as
-- Helper function to split string by character into a list of strings
wordsWhen
::
(
Char
->
Bool
)
->
String
->
[
String
]
wordsWhen
p
s
=
case
dropWhile
p
s
of
""
->
[]
s'
->
w
:
wordsWhen
p
s''
where
(
w
,
s''
)
=
break
p
s'
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment