This file contains hidden or 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
| /* A classical Dancing Links solver with Sudoku and N Queens setups. */ | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <setjmp.h> | |
| // Dancing links Algorithm X exactly from Knuth's paper. | |
| typedef struct data { | |
| struct data *l, *r, *u, *d; |
This file contains hidden or 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
| #include <stdlib.h> | |
| int* getDiagonalOrder(int** matrix, int m, int n) { | |
| int *r = malloc(m * n * sizeof(int)); | |
| int dir = 1, i = 0, j = 0; | |
| for (int k = 0; k < m * n; ++k) { | |
| r[k] = matrix[i][j]; | |
| if (dir > 0) { | |
| if (j == n - 1) { | |
| dir = -1; |
This file contains hidden or 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
| // assumes unsigned is 32 bits | |
| unsigned isqrt1(unsigned x) { | |
| unsigned r = 0, r2 = 0; | |
| for (int p = 15; p >= 0; --p) { | |
| unsigned tr2 = r2 + (r << (p + 1)) + (1u << (p << 1)); | |
| if (tr2 <= x) { | |
| r2 = tr2; | |
| r |= (1u << p); | |
| } | |
| } |
This file contains hidden or 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
| package life; | |
| import java.awt.BorderLayout; | |
| import java.awt.Color; | |
| import java.awt.Dimension; | |
| import java.awt.Graphics; | |
| import java.awt.event.ActionEvent; | |
| import java.awt.event.ActionListener; | |
| import java.util.Random; | |
| import java.util.Timer; |
This file contains hidden or 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
| package levenshtein; | |
| public class Levenshtein { | |
| // Levenshtein distance using O(min |a|, |b|) space. | |
| static int distance(String a, String b) { | |
| // Use minimum buffer size. | |
| if (a.length() < b.length()) | |
| return distance(b, a); | |
| a = a.toLowerCase(); |
This file contains hidden or 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
| <html><head> | |
| <script> | |
| function run(elt) { (function(ctx) { | |
| var render = { | |
| clear: function() { | |
| ctx.fillStyle = 'white' | |
| ctx.clearRect(0, 0, elt.width, elt.height) |
This file contains hidden or 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
| /** | |
| * An experiment in how DAGs work for common subexpression elimination. | |
| */ | |
| package compiler; | |
| import java.io.BufferedReader; | |
| import java.io.FileNotFoundException; | |
| import java.io.FileReader; | |
| import java.io.IOException; | |
| import java.io.Reader; |
NewerOlder