Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update core.clj #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions code-katas-2/src/code_katas_2/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
"Dado un numero cualquiera de secuencias, cada una ya ordenada de menor a mayor, encontrar el numero
mas chico que aparezca en todas las secuencias, las secuencias pueden ser infinitas."
[& seqs]

(defn true-false [x secuencia]
(for [y secuencia]
(contains? (set y) x)
)
)

(defn search2 [secuencias]
(if (some false? (true-false (first (first secuencias)) (rest secuencias)))
#(search2 (concat (list (rest (first secuencias))) (rest secuencias)))
(first (first secuencias))
)
)

(trampoline search2 seqs)
)


Expand All @@ -20,6 +35,15 @@
retorne una nueva coleccion donde el valor es insertado intercalado cada dos argumentos
que cumplan el predicado"
[predicado valor secuencia]
(lazy-seq
(if (not= (count secuencia) 1)
(if (predicado (first secuencia) (second secuencia))
(concat (list (first secuencia) valor) (intercalar predicado valor (rest secuencia)))
(cons (first secuencia) (intercalar predicado valor (rest secuencia)))
)
secuencia
)
)
)


Expand Down