This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Levenshtein(String, String) -> Integer | |
function Levenshtein(a, b) { | |
var n = a.length; | |
var m = b.length; | |
// matriz de cambios mínimos | |
var d = []; | |
// si una de las dos está vacía, la distancia | |
// es insertar todas las otras |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
LevenshteinSubminimal(String A, String B) -> {k: Integer, t: String} | |
A, es la cadena que introduce el usuario | |
B, es la cadena candidata a ser alternativa del usuario | |
k, es la mínima Levenshtein de A sobre todas las subcadenas de B | |
t, es la cadena con menor distancia Levenshtein | |
*/ | |
function LevenshteinSubminimal(A, B) { | |
var a = A.length; | |
var b = B.length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> | |
<title>LevenshteinSubminimal test</title> | |
<style> | |
div { | |
float: left; | |
padding: 5px; | |
border-right: 1px solid gray; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Una forma de acceder al solver, es usando el contexto siempre disponible: | |
var c = SolverContext.GetContext(); | |
// Creamos un modelo vacío, podríamos haberlo leído de disco, ... | |
var m = c.CreateModel(); | |
// Enumeramos los bits: 0, 1, 2, ..., n-1 | |
var b = new Set(0, Math.Ceiling(Math.Log(X) / Math.Log(2)), 1); | |
// Las incógnitas son los bits que tomarán los números Y y Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
min: | |
1 * r1 + 1 * r2 + 1.9 * r3 + 1 * r4 + 1.9 * r5 + 1.9 * r6 + | |
2.7 * r7 + 1 * r8 + 1.9 * r9 + 1.9 * r10 + 2.7 * r11 + | |
1.9 * r12 + 2.7 * r13 + 2.7 * r14 + 3.2 * r15 + 1 * r16 + | |
1.9 * r17 + 1.9 * r18 + 2.7 * r19 + 1.9 * r20 + 2.7 * r21 + | |
2.7 * r22 + 3.2 * r23 + 1.9 * r24 + 2.7 * r25 + 2.7 * r26 + | |
3.2 * r27 + 2.7 * r28 + 3.2 * r29 + 3.2 * r30 + 3.75 * r31; | |
r1+r3+r5+r7+r9+r11+r13+r15+r17+r19+r21+r23+r25+r27+r29+r31=Books1; | |
r2+r3+r6+r7+r10+r11+r14+r15+r18+r19+r22+r23+r26+r27+r30+r31=Books2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Todas las combinaciones de N elementos | |
void Combinaciones( int N ) { | |
for( int n = 0; n < 1 << N; n++ ) { | |
// Usar combinación. | |
} | |
} | |
// Combinaciones de N elementos tomados de M en M | |
void Combinaciones( int N, int M ) { | |
for( int n = 0; n < 1 << N; n++ ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct _Partida { | |
unsigned short a:1; | |
unsigned short b:1; | |
unsigned short c:1; | |
unsigned short d:1; | |
unsigned short e:1; | |
unsigned short f:1; | |
unsigned short g:1; | |
unsigned short h:1; | |
unsigned short i:1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# %edi es el parámetro | |
movl %edi, %edx | |
movl %edi, %eax | |
andl $7, %edx | |
cmpb $7, %dl | |
je .L9 | |
movl %edi, %edx | |
andl $56, %edx | |
cmpb $56, %dl | |
je .L9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Buscando un cero (eg. la longitud de la cadena) | |
int strlen(char *s) { | |
int l = 0; | |
while(*s++) l++; | |
return l; | |
} | |
// Buscando la primera aparición de un caracter dado | |
int strpos(char *s, char c) { | |
int l = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://graphics.stanford.edu/~seander/bithacks.html | |
#define haszero(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL) | |
// en 4 operaciones indica si un byte de entre todos es 0 | |
// para 64 bits será, lógicamente | |
#define haszero(v) (((v) - 0x0101010101010101UL) & ~(v) & 0x8080808080808080UL) |
OlderNewer