Skip to content

Instantly share code, notes, and snippets.

View lnds's full-sized avatar

Eduardo Díaz lnds

View GitHub Profile
@lnds
lnds / is_digit.erl
Created January 11, 2016 20:57
guards en Erlang
is_digit(C) when C >= $0, C=<$9 -> true;
is_digit(_) -> false.
@lnds
lnds / for.go
Created January 11, 2016 21:38
For y range en Go
num := make([]int, 0, tam)
for i, c := range accion {
if !unicode.IsDigit(c) {
return nil
} else if i >= tam {
return nil
} else {
digit := int (c - '0')
for _, d := range num {
if digit == d { return nil }
@lnds
lnds / enumerate.rs
Last active January 11, 2016 21:43
For con enumerate en Rust
for (i,c) in accion.chars().enumerate() {
if !c.is_digit(10) { return Error }
else if i >= tam { return Error }
else {
let digito = c.to_digit(10).unwrap();
if num.contains(&digito) { return Error }
num.push(digito)
}
}
@lnds
lnds / enumerate.swift
Last active January 11, 2016 21:44
For con enumerate en swift
for (i,c) in chars.enumerate() {
if i >= tam {
return nil
} else if c < "0" || c > "9" {
return nil
} else {
let digito = Int(String(c))!
if num.contains(digito) {
return nil
}
@lnds
lnds / for.kt
Created January 11, 2016 21:50
Fors en kotlin
for (it in accion.withIndex()) {
if (!it.value.isDigit())
return null
if (it.index >= tam)
return null
}
for ((i,n) in num.withIndex())
for ((j,m) in sec.withIndex())
if (n == m) {
@lnds
lnds / zipwithindex.scala
Last active January 11, 2016 21:53
For en Scala
for ((n,i) <- num.zipWithIndex; (m,j) <- sec.zipWithIndex)
yield if (n == m) if (i == j) 'F' else 'T'
@lnds
lnds / tyf.hs
Created January 12, 2016 02:00
Toques y Famas calculados en Haskell
toques_y_famas [] _ _ = (0,0)
toques_y_famas (n:ns) (x:xs) ys
| n == x = (t,1+f)
| n `elem` ys = (t+1, f)
| otherwise = (t,f)
where (t,f) = (toques_y_famas ns xs ys)
@lnds
lnds / tyf.erl
Created January 12, 2016 02:15
toques y famas en erlang
contar_toques_y_famas(Num,Sec) -> tyf(Num,Sec,Sec).
tyf([],_,_) -> {0,0};
tyf([HNS|TNS],[HXS|TXS],YS) ->
{T,F} = tyf(TNS,TXS,YS),
if HNS =:= HXS -> {T,F+1};
HNS =/= HXS -> {T+toque(HNS,YS),F}
end.
toque(X,XS) -> IN = lists:member(X,XS), if IN =:= true -> 1; IN =:= false -> 0 end.
@lnds
lnds / tyf.fs
Created January 12, 2016 02:17
Toque y fama en F#
let comparar num sec =
let rec tyf ns xs ys =
match (ns, xs, ys) with
| ([], _, _) -> (0,0)
| (n::ns, x::xs, ys) ->
let (t,f) = tyf ns xs ys
if n = x then (t,f+1) else (if List.exists (fun x -> x = n) ys then (t+1,f) else (t,f))
tyf num sec sec
@lnds
lnds / gano.clj
Created January 12, 2016 02:47
gano?
(defn gano? [num sec tam]
(let [f (famas num sec) t (- (toques num sec) f)]
(println "tu ingresaste" num)
(println "resultado:" t "Toques, " f "Famas\n")
(= tam f)))