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
beginfig(1) | |
path digit; | |
numeric d; | |
string digit_string; | |
u := 5mm; | |
max_base = 10; | |
max_num = 99; | |
digit_string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
color c_d[]; |
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
22225 13333 11444 | |
23333 12255 11444 | |
23333 22225 11444 | |
33333 12255 11444 | |
33333 22225 11444 | |
33333 22235 11444 | |
33333 22245 11444 | |
33333 22255 11444 | |
33333 22255 11445 | |
33333 22255 12444 |
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 com.google.common.base.Optional; | |
import com.google.common.collect.Lists; | |
import java.util.Iterator; | |
import java.util.NoSuchElementException; | |
public class A { | |
public static <T> T getOnlyElement(Iterable<T> xs, Optional<T> e, Optional<T> xx) { | |
Iterator<T> i = xs.iterator(); | |
if (!i.hasNext()) { | |
if (e.isPresent()) return e.get(); |
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
int power(int x, unsigned int y) { | |
if (y == 0) return 1; | |
if (y == 2) return x * x; | |
if (y&1) return x * power(power(x, y/2),2); | |
return power(power(x, y/2),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
from sys import stdin, stdout | |
import random, math | |
def tour_length(G, xs): | |
s = sum(G[xs[i-1]][xs[i]] for i in range(len(xs))) | |
n = len(xs) | |
return s + min(G[0][xs[i]] - max(G[xs[i]][xs[(i+1)%n]], G[xs[i]][xs[(i-1)%n]]) | |
for i in range(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
#!/usr/bin/env python3 | |
from copy import copy | |
from math import atan2, pi, sqrt | |
from random import randrange, seed, shuffle | |
from sys import exit, stderr | |
from time import time | |
eps = 1e-9 |
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
# NOTES: | |
# - I didn't pay attention to what happens for lists of even length | |
# - Since the data is random, the algorithms need not be randomized. I put | |
# randomization in because calls to randrange/sample/etc might take | |
# significant time, and it's not really OK to ignore that time. | |
# - Since the data is random, Python's sort should be disadvantaged, at least | |
# when M >> N. (The main idea of Timsort is that it exploits patterns | |
# in data.) | |
# - As expected, Timsort does better when N>M than when M>N. I didn't expect it | |
# to bo _so_ much better, though. |
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 Data.Array | |
import Debug.Trace | |
tabulate :: (Ix a) => (a,a) -> (a -> b) -> Array a b | |
tabulate bounds f = array bounds [(i,f i) | i <- range bounds] | |
dp :: (Ix a) => (a,a) -> ((a->b) -> a -> b) -> a -> b | |
dp bounds f = (memo!) where | |
memo = tabulate bounds (f (memo!)) |
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
\documentclass{article} | |
%include polycode.fmt | |
\begin{document} | |
> import Array | |
> import Data.Bits | |
> import Data.Char | |
> import Data.Function | |
> import qualified Data.IntSet as IS |
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 qualified Data.IntMap as M | |
import Maybe | |
fillBin capacity ws@(w:ws') weight count | |
| newWeight > capacity = (ws, weight, count) | |
| otherwise = fillBin capacity ws' newWeight (succ count) | |
where newWeight = weight + w | |
go period capacity bins weights acc state seen | |
| bins == 0 = acc |
OlderNewer