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

final #1

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions code-katas-1/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="C:\Users\Max\Documents\GitHub\katas\code-katas-1\target\classes"/>
<classpathentry kind="lib" path="C:\Users\Max\.m2\repository\clojure-complete\clojure-complete\0.2.3\clojure-complete-0.2.3.jar"/>
<classpathentry kind="lib" path="C:\Users\Max\.m2\repository\org\clojure\tools.nrepl\0.2.3\tools.nrepl-0.2.3.jar"/>
<classpathentry kind="lib" path="C:\Users\Max\.m2\repository\org\clojure\clojure\1.5.1\clojure-1.5.1.jar"/>
<classpathentry kind="src" path="test"/>
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
20 changes: 20 additions & 0 deletions code-katas-1/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>code-katas-1</name>
<comment>FIXME: write description</comment>
<projects/>
<buildSpec>
<buildCommand>
<name>ccw.builder</name>
<arguments/>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments/>
</buildCommand>
</buildSpec>
<natures>
<nature>ccw.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions code-katas-1/.settings/ccw.repl.cmdhistory.prefs

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions code-katas-1/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
4 changes: 3 additions & 1 deletion code-katas-1/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]])
:dependencies [[org.clojure/clojure "1.5.1"]]
:plugins [[lein2-eclipse "2.0.0"]]
)
57 changes: 55 additions & 2 deletions code-katas-1/src/code_katas_1/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,113 @@
"Escribir una funcion que retorne solamente los numeros impares de
una secuencia"
[s]
(for [x s :when (odd? x)] x)
)

(defn nil-key
"Escribir una funcion que dada una clave y un mapa, devuelva true, solamente si el mapa
contiene una entrada con esa clave, y su valor es nil"
[k m])
[k m]
(if (contains? m k) (if (nil? (k m)) true false) false)
)

(defn range
"Escribir una funcion que cree una lista de enteros en un rango dado.
Restricciones: range"
[start end]
(if (< start end) (take (- end start) (iterate inc start)) "Inicio debe ser mas pequeño que final")
)

(defn compress-sequence
"Escribir una funcion que elimine los duplicados consecutivos
de una secuencia"
[s]

(defn secuencia [x sec temp]
(if (= x "")
(secuencia (aget sec 0) (to-array (into [] (drop 1 sec))) (conj temp (aget sec 0)))
(if (not (empty? sec))
(if (not= x (aget sec 0))
(secuencia (aget sec 0) (to-array (into [] (drop 1 sec))) (conj temp (aget sec 0)))
(secuencia x (to-array (into [] (drop 1 sec))) temp))
temp
)
)
)
(secuencia "" (to-array s) [])
)

(defn max-value
"Escribir una funcion que reciba un numero variable de parametros
y retorne el que tenga el valor mayor
Restricciones: max y max-key"
[& args])
[& args]
(defn max-value2 [maxim pmts]
(if (not (empty? pmts))
(if (> (first pmts) maxim)
(max-value2 (first pmts) (into [] (drop 1 pmts)))
(max-value2 maxim (into [] (drop 1 pmts)))
)
maxim
)
)
(max-value2 0 args)
)

(defn split-two
"Escribir una funcion que parta una secuencia en dos partes
Restricciones: split-at"
[length s]
(into [] (into [] (for [x (take length s)] x)) (into [] (drop length s)) )
)

(defn inter-two
"Escribir una funcion que reciba dos secuencias y retorne el primero de cada una,
luego el segundo de cada una, luego el tercero, etc.
Restricciones: interleave"
[s1 s2]

(reduce
(fn [a b]
(if (not= (- b 1) 0)
(concat (into [] a) (vector (aget (to-array s1) (- b 1)) (aget (to-array s2) (- b 1))))
(list (aget (to-array s1) (- b 1)) (aget (to-array s2) (- b 1)))
)
)
(range (+ 1 (if (< (count s1) (count s2)) (count s1) (count s2))))
)
)

(defn retrieve-caps
"Escribir una funcion que reciba un string y devuelva un nuevo string conteniendo
solamente las mayusculas."
[text]
(reduce (fn [a b] (if (= (str b) (clojure.string/upper-case b)) (str a b) a)) (to-array text))
)

(defn find-truth
"Escribir una funcion que tome un numero variable de booleans, y devuelva true
solamente si alguno de los parametros son true, pero no todos son true. En otro
caso debera retornar false"
[& xs]
(if (some false? xs)
(if (some true? xs) true false)
false
)
)

(defn zip-map
"Escribir una funcion que reciba un vector de claves y un vector de valores, y
construya un mapa a partir de ellos.
Restricciones: zipmap"
[k v]
(reduce
(fn [a b]
(if (not= 0 a)
(merge (into {} (vector(vector (nth k (- b 1)) (nth v (- b 1))))) a)
(into {} (vector(vector (nth k 0) (nth v 0))))
)
)
(range 0 (+ 1 (count k)))
)
)
40 changes: 40 additions & 0 deletions code-katas-2/code-katas-2/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="test">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="dev-resources">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="resources">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="target/classes">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="ccw.LEININGEN_CONTAINER">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="code-katas-2/target/native/windows/x86_64"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="classes">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
9 changes: 9 additions & 0 deletions code-katas-2/code-katas-2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
29 changes: 29 additions & 0 deletions code-katas-2/code-katas-2/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>code-katas-2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>ccw.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>ccw.leiningen.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>ccw.leiningen.nature</nature>
<nature>ccw.nature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions code-katas-2/code-katas-2/.settings/ccw.repl.cmdhistory.prefs

Large diffs are not rendered by default.

Loading