Skip to content

Instantly share code, notes, and snippets.

View javascripter's full-sized avatar

javascripter

View GitHub Profile
#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');
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)
-- 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
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
if exists("loaded_guessindent")
finish
endif
function! GuessIndent()
ruby <<EOS
def guess_indent
i = 0
b = VIM::Buffer.current
1.upto(b.count) {|i|
#!/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"),
#!/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)
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)
#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;
#!/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)) {