Skip to content

Instantly share code, notes, and snippets.

View kawakami-o3's full-sized avatar

Hayato Mikami kawakami-o3

  • Japan, Tokyo
View GitHub Profile
@kawakami-o3
kawakami-o3 / gist:1161104
Created August 21, 2011 20:21
Why is this short code incorrect, "Runtime Error"?
#!/usr/bin/ruby
# http://www.codechef.com/COOK13/problems/DRAGNXOR/
n = gets.to_i
n.times do
arr = gets.split.map {|i| i.to_i}
bit = 0
[1,2].each do |i|
while arr[i] > 0
bit += arr[i] % 2
arr[i] /= 2
@kawakami-o3
kawakami-o3 / 084d.rb
Created August 30, 2011 13:41
Codeforces #84 Div2 D ("1 20 100 120 5" -> "0.2" on local, but "0.15" on site)
#!/usr/bin/env ruby
args = STDIN.gets.split(" ").map{|i| i.to_i}
argp = args[0..1]
argv = args[2..3]
argk = args[4]
min = [argp[0],argv[0]].min
max = [argp[1],argv[1]].max
@kawakami-o3
kawakami-o3 / IrcSenderSimple.java
Created December 17, 2011 07:38
Simple IRC Client in Java
import java.net.*;
import java.io.*;
import java.util.*;
class IrcSenderSimple {
static void sendString(BufferedWriter bw, String str) {
try {
bw.write(str + "\r\n");
bw.flush();
}
@kawakami-o3
kawakami-o3 / Fib.java
Created July 22, 2012 06:48
Fibonacci in Java
import java.util.*;
public class Fib {
Map<Integer,Long> memo;
public Fib() {
memo = new HashMap<Integer,Long>();
memo.put(0,0L);
memo.put(1,1L);
}
@kawakami-o3
kawakami-o3 / gist:3609211
Created September 3, 2012 13:05
Stack space overflow: current size 8388608 bytes.
sum :: Int -> Int
sum = sum' 0
where
sum' acc n | n<1 = acc
| otherwise = sum' (acc+n) (n-1)
main = do
putStrLn (show (Main.sum (2^24)))
@kawakami-o3
kawakami-o3 / gist:3683302
Created September 9, 2012 08:19
Start Haskell2 - Exercise 9
import System.Random
import System.IO (hFlush, stdout)
exactNum :: String -> String -> Int
exactNum a b = exactNum' 0 a b
where
exactNum' n [] [] = n
exactNum' n (a:as) (b:bs) = exactNum' (if a==b then (n+1) else n) as bs
matchNum :: String -> String -> Int
@kawakami-o3
kawakami-o3 / gist:3692313
Created September 10, 2012 17:26
exercise
import Text.Printf
printer :: [[Int]] -> IO ()
printer = mapM_ (\x -> do
mapM (printf "%3d") x
putStrLn "")
main = printer [[x*y|x<-[1..9]]|y<-[1..9]]
@kawakami-o3
kawakami-o3 / gist:3844156
Created October 6, 2012 05:58
インデント処理
" 実現したい機能
" * >>, << でインデント調整
" * ^で先頭へ
" * リターンで">"を自動挿入
" * 言語用自動インデント機能の挿入
" Ref.
" http://www.ibm.com/developerworks/jp/linux/library/l-vim-script-1/
" http://www.ibm.com/developerworks/jp/linux/library/l-vim-script-2/
" http://nanasi.jp/articles/code/screen/cursor.html
"
@kawakami-o3
kawakami-o3 / ReferenceTest.java
Last active December 12, 2015 06:39
ReferenceTest
import java.io.*;
import java.util.*;
public class ReferenceTest {
public static class Base {
public int value = 0;
}
public static class Wrapper {
private Base base;
@kawakami-o3
kawakami-o3 / gist:8798455
Created February 4, 2014 05:10
Watir::Browswer.crawl
require 'watir-webdriver'
class Watir::Browser
def visited? url
if @history == nil
return false
end
return @history.index(url) != nil
end