Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
9
Task/Soundex/Befunge/soundex.bf
Normal file
9
Task/Soundex/Befunge/soundex.bf
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
>:~>:48*\`#v_::"`"`\"{"\`*v
|
||||
^$$_v#!*`*8 8\`\"["::-**84<
|
||||
>$1^>:88*>v>$$1->vp7+2\"0"<
|
||||
|!-g71:g8-< >1+::3`!>|
|
||||
>17p\:!v@p7 10,+55$$<$
|
||||
v+1p7+2_\$17g\17gv>>+:>5`|2
|
||||
v$$:$$_^#\<1!-"0"<^1,<g7:<<
|
||||
v??????????????????????????
|
||||
v01230120022455012623010202
|
||||
27
Task/Soundex/Clojure/soundex-2.clj
Normal file
27
Task/Soundex/Clojure/soundex-2.clj
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
;;; With proper consecutive duplicates elimination
|
||||
|
||||
(defn get-code [c]
|
||||
(case c
|
||||
(\B \F \P \V) 1
|
||||
(\C \G \J \K
|
||||
\Q \S \X \Z) 2
|
||||
(\D \T) 3
|
||||
\L 4
|
||||
(\M \N) 5
|
||||
\R 6
|
||||
nil)) ;(\A \E \I \O \U \H \W \Y)
|
||||
|
||||
(defn reduce-fn [acc nxt]
|
||||
(let [next-code (get-code nxt)]
|
||||
(if (and (not= next-code (last acc))
|
||||
(not (nil? next-code)))
|
||||
(conj acc next-code)
|
||||
acc)))
|
||||
|
||||
(defn soundex [the-word]
|
||||
(let [[first-char & the-rest] (.toUpperCase the-word)
|
||||
next-code (get-code (first the-rest))]
|
||||
(if (nil? next-code)
|
||||
(recur (apply str first-char (rest the-rest)))
|
||||
(let [soundex-nums (reduce reduce-fn [] the-rest)]
|
||||
(apply str first-char (take 3 (conj soundex-nums 0 0 0)))))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue