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
/* | |
* A parameterized rectangular grid maze generator. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
// Maze data bits. | |
#define VISITED 1 | |
#define RIGHT 2 |
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
import java.util.ArrayList; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.NavigableSet; | |
import java.util.Set; | |
import java.util.TreeSet; | |
import java.util.stream.IntStream; | |
import static java.util.Comparator.comparing; | |
public class Dijkstra { |
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
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct list_node_s { | |
struct list_node_s *next; | |
int val; | |
} LIST_NODE; | |
LIST_NODE *sort(LIST_NODE *a) { | |
if (!a || !a->next) return a; |
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
#include <stdio.h> | |
#include <stdlib.h> | |
void sort(int *a, int n) { | |
for (int i = 1; i < n; ++i) { | |
int j, t = a[i]; | |
for (j = i; j > 0 && a[j - 1] > t; --j) a[j] = a[j - 1]; | |
a[j] = t; | |
} | |
} |
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
#include <stdio.h> | |
#include <stdlib.h> | |
void sift_down(int *a, int n, int j) { | |
int j_rgt, val = a[j]; | |
while ((j_rgt = 2 * j + 2) <= n) { | |
int j_lft = j_rgt - 1; | |
if (j_rgt == n || a[j_lft] > a[j_rgt]) { | |
if (val >= a[j_lft]) break; | |
a[j] = a[j_lft]; |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
void sort(int *a, int n) { | |
if (n <= 1) return; | |
int m = (n + 1) / 2; | |
sort(a, m); | |
sort(a + m, n - m); | |
int b[m]; |
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
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct edge_s { | |
struct edge_s *next; | |
int to; | |
} Edge; | |
typedef struct vertex_s { | |
Edge *edges; |
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
#include <stdio.h> | |
#include <stdlib.h> | |
static int med3(int a, int b, int c) { | |
return a < b | |
? c < a ? a : (c < b ? c : b) | |
: c > a ? a : (c > b ? c : b); | |
} | |
static void swap(int *a, int i, int j) { |
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
# For any 0 <= k < fact(n), return a unique permutation of [0..n-1]. | |
# Functional inverse of number_from_perm(). | |
def perm_from_number(n, k): | |
a = list(range(n)) | |
p = [] | |
for d in range(2, n + 1): | |
p.append(k % d) | |
k //= d | |
t = n - 1 | |
for i in reversed(p): |
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
#include <stdio.h> | |
#include <stdlib.h> | |
static int med3(int a, int b, int c) { | |
return a < b | |
? c < a ? a : (c < b ? c : b) | |
: c > a ? a : (c > b ? c : b); | |
} | |
static void swap(int *a, int i, int j) { |