Skip to content

Instantly share code, notes, and snippets.

View lnds's full-sized avatar

Eduardo Díaz lnds

View GitHub Profile
@lnds
lnds / gist:2017018
Created March 11, 2012 16:26
Determinación si un año es bisiesto
// este es un ejemplo para www.programando.org
/* return 1 si el año es bisiesto, 0 si no lo es.
Esta función es muy simple y no considera hechos históricos asociados al calendario gregoriano.*/
int is_leap(int year)
{
return ((year % 4) == 0) && ( (year % 100) != 0 || (year % 400) == 0 );
}
@lnds
lnds / siracusa-1.c
Created May 2, 2012 01:42
solución problema de Siracusa
#include <stdlib.h>
#include <stdio.h>
typedef unsigned long long INT;
INT orbita(INT n) {
INT largo = 0;
do {
n = (n % 2) == 0 ? n / 2 : n*3+1;
largo++;
@lnds
lnds / siracusa-2.c
Created May 5, 2012 14:05
Mejorando la solución al problema siracusa, segundo intento
INT orbita(INT n) {
INT largo = 0;
do {
if (n&0x01)
n = ((n<<1)|1)+n;
do {
n = n>>1;
largo++;
} while(!(n&0x01));
} while (n>1);
@lnds
lnds / hamming0_lnds.py
Created July 8, 2012 18:08
Haming Solucion 0 en Python (www.programando.org)
def hamming(p1,p2,p3):
yield 1
m2 = times(p1, hamming(p1,p2,p3))
m3 = times(p2, hamming(p1,p2,p3))
m5 = times(p3, hamming(p1,p2,p3))
for h in merge(merge(m2, m3), m5):
yield h
@lnds
lnds / ofhamming.c
Created July 8, 2012 20:15
Oscura, pero eficiente solución al problema de hamming
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*
**
** Adaptación del código de Jed Davis
** En Lambda The Ultimate: http://lambda-the-ultimate.org/node/608#comment-5267
*/
@lnds
lnds / flor.lsys
Created September 16, 2012 16:15
Solucion a la flor
lar 20
ang 30
axi D
D:LALALALALALA
L:C++C++C++C++C++C++C
C:FFC
U:------
A:Uff+F+Fb-b-bb++++
iter 4
@lnds
lnds / gist:3862218
Created October 9, 2012 23:49
programa1 fortran
C --- PROGRAMA 1 -----
read 6, i,k,j
99 if(i .lt. j)goto 33
goto 55
33 i=j
goto 99
55 k=j+1
stop
@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
@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 / 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 {
...
}