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
# $ perl a.pl 1 1 1 1 1 3 4 4 4 4 4 | |
# len: 5 nums: 4 1 | |
# $ perl a.pl 1 1 1 1 1 3 4 4 4 4 | |
# len: 5 nums: 1 | |
sub f { | |
my ($x, @xs) = @_; | |
if (not @xs) { | |
(1, $x, 0, ()); | |
} else { |
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
# $ perl a.pl 1 1 1 1 1 3 4 4 4 4 4 | |
# len: 5 nums: 4 1 | |
# $ perl a.pl 1 1 1 1 1 3 4 4 4 4 | |
# len: 5 nums: 1 | |
sub f { | |
my ($x, @xs) = @_; | |
if (not @xs) { | |
(1, $x, 0, ()); | |
} else { |
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
f :: [Int] -> [Int] | |
f [x] = [1, x, 0] | |
f (x:xs) = | |
if h == x then | |
if hl + 1 > yl then [hl + 1, h, 0] | |
else [hl + 1, h, yl] ++ ys | |
else | |
if hl == yl then [1, x, yl] ++ h:ys | |
else if hl > yl then [1, x, hl, h] | |
else [1, x, yl] ++ ys |
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
tmp=$(cat <<EOPY | |
import sys | |
for line in sys.stdin: | |
print line.replace( 'asdf', 'ASDF' ) | |
print(line) | |
EOPY) | |
echo "asdf.asdf.asdf.e" | python -c "$tmp" |
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
# https://www.facebook.com/LCamel/posts/380886841959001 | |
print join(",", "xxxx;x,x,x,x,x,x,x," =~ /^ | |
(x?)(x?)(x?)(x?) .* ; | |
(?: x\1 | \2 | \4 ), | |
(?: \1 | x\3 | \4 ), | |
(?: \1 | x\2 | x\4 ), | |
(?: \2 | x\3 | x\4 ), | |
(?: x\1 | \3 | x\4 ), | |
(?: \1 | \2 | \3 ), |
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> | |
unsigned char f(int i, int j) { | |
unsigned char c1 = -1 << i; | |
unsigned char c2 = ~(-1 << ++j); | |
unsigned char c3 = c1 & c2; | |
printf("%d\n", c1); | |
printf("%d\n", c2); | |
printf("%d\n", c3); | |
} |
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: https://www.facebook.com/qingwang/posts/10151427723443879 | |
var output = ["剪刀", "石頭", "布"]; | |
var who = ["女孩", "男孩"]; | |
function foo(depth) { | |
if (depth == 0) { | |
return ["女孩想出石頭", 1]; | |
} else { | |
var other = foo(depth - 1); | |
var my = (other[1] + 3 - 1) % 3; | |
return [who[depth % 2] + "想: (" + other[0] + "), 所以自己出" + output[my], my]; |
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
object ImpossiblePuzzle extends App { | |
type XY = (Int, Int) | |
val xys0 = for { | |
x <- 1 to 100 | |
y <- 1 to 100 | |
if 1 < x && x < y && x + y < 100 | |
} yield (x, y) | |
def sum(xy: XY) = xy._1 + xy._2 | |
def prod(xy: XY) = xy._1 * xy._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
my $delta = shift; # ms | |
while (<>) { | |
if (/^(..):(..):(..),(...) --> (..):(..):(..),(...)/) { | |
my $t1 = conv($1, $2, $3, $4, $delta); | |
my $t2 = conv($5, $6, $7, $8, $delta); | |
print "$t1 --> $t2\n"; | |
} else { | |
print; | |
} |
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
# This is the default .slate file. | |
# If no ~/.slate file exists this is the file that will be used. | |
config defaultToCurrentScreen true | |
config nudgePercentOf screenSize | |
config resizePercentOf screenSize | |
# Resize Bindings | |
#bind right:alt resize +10% +0 | |
#bind left:alt resize -10% +0 |