Skip to content

Instantly share code, notes, and snippets.

View lnds's full-sized avatar

Eduardo Díaz lnds

View GitHub Profile
@lnds
lnds / validar.hs
Created January 11, 2016 20:08
selección en Haskell
validar n xs
| length num /= n = []
| otherwise = num
where num = if not (all isDigit xs) then [] else remover_dups xs
@lnds
lnds / ifs.kt
Created January 10, 2016 18:21
Ifs en Kotlin
if (!it.value.isDigit())
return null
if (it.index >= tam)
return null
else {
val digit = it.value.toInt() - '0'.toInt()
if (digit in num) return null
num = num.plus(digit)
}
@lnds
lnds / validar.fs
Created January 10, 2016 16:57
Validar en F#
let validar tam accion =
let cars = [for c in accion -> c]
if List.exists (fun c -> not (Char.IsDigit c)) cars then List.empty<int>
else
let org = List.map (fun c -> (int c) - (int '0')) cars
let num = List.distinct org
if (List.length org <> List.length num) || (List.length num <> tam) then List.empty<int>
else num
@lnds
lnds / validar.scala
Created January 10, 2016 16:52
Otra forma de implementar validar
def validar(tam:Int, accion:String) : Option[Array[Int]] =
if (accion.exists(c => !c.isDigit) None
else {
val num = accion.map(c => c.toInt - '0'.toInt).distinct
if (num.length == tam && num.length == accion.length)
Some(num.toArray)
else
None
}
@lnds
lnds / ifs.scala
Created January 10, 2016 16:43
Ejemplo de If en Scala. Notar la primera condición
def validar(tam:Int, accion:String) : Option[Array[Int]] =
if (accion.exists(!_.isDigit))
None
else {
val num = accion.map(_.toInt - '0'.toInt).distinct
if (num.length == tam && num.length == accion.length)
Some(num.toArray)
else
None
}
@lnds
lnds / ifs.rust
Last active January 10, 2016 16:44
If en Rust
if !c.is_digit(10) { return Error }
else if i >= tam { return Error }
else { ... }
@lnds
lnds / ifs.swift
Created January 10, 2016 16:30
If en Swift
if i >= tam {
return nil
} else if c < "0" || c > "9" {
return nil
} else {
...
}
@lnds
lnds / ifs.go
Last active January 10, 2016 16:37
If en Go
if !unicode.IsDigit(c) {
return nil
} else if i >= tam {
return nil
} else {
...
}
@lnds
lnds / gist:5424160
Created April 20, 2013 00:32
Clase que permite abrir archivos detectando su encoding en forma automática, muy útil para trabajar con archivos codificados en WIndows Ansi, UTF8, Unicode, etc. Un problema que se está haciendo demasiado frecuente. Usa la biblioteca universalchardet de Mozilla
import org.mozilla.universalchardet.UniversalDetector;
import java.io.*;
import java.nio.charset.Charset;
public class DetectEncoding {
private static final int BUF_SIZE = 4096;
// open a BufferedReader detect encoding
@lnds
lnds / gist:3862222
Created October 9, 2012 23:49
Programa2 fortran
C --- PROGRAMA 2 -----
read6,i,k,j
if(i.lt.j)goto12345
77 k=j+1
goto5555
12345 i=j
if(i.lt.j)goto12345
goto77
88 goto88
5555 stop