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
| import java.util.*; | |
| public final class PathFinding { | |
| static final class State { | |
| final int ax, ay, bx, by; | |
| final int hash; | |
| State(int ax, int ay, int bx, int by) { | |
| this.ax = ax; |
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
| import java.util.*; | |
| public final class Circuits { | |
| public static int howLong(String[] connects, String[] costs) { | |
| final int size = connects.length; | |
| final int[][] m = new int[size][size]; | |
| for (int i=0; i<size; ++i) { | |
| String c = connects[i]; |
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 <stdio.h> | |
| struct padded { | |
| short s; | |
| int i; | |
| }; | |
| int main(int argc, char **argv) { | |
| // this should give in memory (8 bytes): | |
| // 0xffff1234, 0x00005678 |
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 <stdio.h> | |
| #include <stdlib.h> | |
| int intcmp(const void *a, const void *b) { | |
| return *((int *)a) - *((int *)b); | |
| } | |
| int min_coins(int coins[], size_t ncoins, int target) { | |
| if (ncoins <=0 ) return 0; | |
| qsort(coins, ncoins, sizeof(int), &intcmp); |
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
| public class ZigZag { | |
| public static int longestZigZag(int[] sequence) { | |
| final int n = sequence.length; | |
| int[] positive = new int[n]; | |
| int[] negative = new int[n]; | |
| for (int i=0; i<n; ++i) { | |
| positive[i] = negative[i] = 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
| public class BadNeighbors { | |
| public static void main(String[] args) { | |
| int[] collections = new int[args.length]; | |
| for (int i=0; i<args.length; ++i) { | |
| collections[i] = Integer.parseInt(args[i]); | |
| } | |
| System.out.printf("%d\n", maxDonations(collections)); | |
| } |
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
| subset :: Int -> Int -> [[Int]] | |
| subset 0 _ = [[]] | |
| subset _ 0 = [[]] | |
| subset n k = [i:y | i <- [k..n], y <- subset (i-1) (k-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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <assert.h> | |
| #define max(A, B) ((A) > (B) ? (A) : (B)) | |
| #define min(A, B) ((A) < (B) ? (A) : (B)) | |
| int contained(int *cont, size_t len) { | |
| if (len == 0) { | |
| return 0; |
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
| import java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.concurrent.*; | |
| public class InterruptThreadPools<V> { | |
| private final ExecutorService threadPool = Executors.newCachedThreadPool(); | |
| private final CompletionService<V> completionService = new ExecutorCompletionService<>(threadPool); | |
| private final BlockingQueue<Future<V>> tasks = new LinkedBlockingQueue<>(); |
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
| import java.io.*; | |
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.List; | |
| public class OOSTest { | |
| public static void main(String[] args) throws Exception { | |
| try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | |
| ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream)) { |