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 <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
inline int bit2(char *bits) { | |
int n = 0; | |
assert(*bits); | |
for (; *bits != '\0'; bits++) { | |
assert(*bits == '0' || *bits == '1'); |
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
isqrt :: Integer -> Integer | |
isqrt n | n >= 0 = f n 0 | |
| otherwise = error "domain error" | |
where | |
f n i | n < 0 = i - 1 | |
|otherwise = f (n - (i * 2 + 1)) (i + 1) |
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
-- Sieve of Eratosthenes | |
primes :: [Integer] | |
primes = f [2..] | |
where | |
f (x:xs) = x : [n | n <- xs, n `mod` x /= 0] | |
main :: IO () | |
main = mapM_ print primes |
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
data Rank = S | A | B | C | D | E | F | |
deriving (Eq, Show) | |
instance Ord Rank where | |
S > S = False | |
S > _ = True | |
_ > S = False | |
x > y = (show x) < (show y) -- A < Z in ASCII Code. | |
x <= y = not $ x > y |
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
if exists("loaded_guessindent") | |
finish | |
endif | |
function! GuessIndent() | |
ruby <<EOS | |
def guess_indent | |
i = 0 | |
b = VIM::Buffer.current | |
1.upto(b.count) {|i| |
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 ruby | |
def guess_indent(file) | |
i = 0 | |
file.each_line.with_index {|line, i| | |
break if i > 3 | |
match = /^\s+/.match(line) | |
next unless match | |
return { | |
:tab? => line.start_with?("\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
#!/usr/bin/env python | |
# encoding:utf-8 | |
class WeightedList: | |
def __init__(self, lis): | |
self.list = lis | |
self.total = sum(map(lambda v: v[0], self.list)) | |
def choice(self): | |
import random | |
index = random.randint(0, self.total) |
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
def rot13(s): | |
table = dict(zip("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm") | |
) | |
result = [] | |
for i in s: | |
if i in table: | |
result.append(table[i]) | |
else: | |
result.append(i) | |
return "".join(result) |
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 <time.h> | |
#include <math.h> | |
#include <string.h> | |
#include <ncurses.h> | |
#include <unistd.h> | |
int main(int argc, char *argv[]) { | |
time_t nowtime; | |
struct tm now; |
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/perl | |
package FizzBuzz; | |
use strict; | |
use warnings; | |
use feature qw(switch say state); | |
our $VERSION = v0_0_1; | |
sub fizzbuzz { | |
unless (defined(wantarray)) { |