-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
130 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
(ns ars-magna.solver | ||
(:require | ||
[clojure.string :as s] | ||
[clojure.math.combinatorics :as c] | ||
[ars-magna.dict :refer :all])) | ||
|
||
(defn multi-word [index word min-size prefix] | ||
(if (empty? word) | ||
(s/trim prefix) | ||
(flatten | ||
(for [w (find-in index word min-size :en-GB)] | ||
(multi-word | ||
index | ||
(remaining-chars word w) | ||
min-size | ||
(str w " " prefix)))))) | ||
(defn multi-word | ||
([index word min-size] | ||
(multi-word index word min-size nil)) | ||
|
||
([index word min-size prefix] | ||
(if (empty? word) | ||
(s/trim prefix) | ||
(flatten | ||
(for [w (find-in index word min-size :en-GB)] | ||
(multi-word | ||
index | ||
(remaining-chars word w) | ||
min-size | ||
(str w " " prefix))))))) | ||
|
||
(defn longest [index word min-size] | ||
(->> | ||
(range min-size (inc (count word))) | ||
(mapcat #(map sort (c/combinations word %))) | ||
(mapcat index))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters