Skip to content

Instantly share code, notes, and snippets.

@yasuharu519
yasuharu519 / toggle_switch_pattern
Last active December 17, 2015 19:38
CodeIQ - The Essence of Programming toggle switch
1111111111
0000000000
1111111110
0000000001
1111111100
0000000011
1111111101
0000000010
1111111001
0000000110
# coding: utf-8
import random
def quick_sort(inlist):
if len(inlist) <= 1:
return inlist
middle = len(inlist) / 2
pivot = inlist.pop(middle)
left, right = [], []
for i in inlist:
@yasuharu519
yasuharu519 / merge_sort.py
Last active December 16, 2015 00:59
merge sort
# coding: utf-8
# ソーティング練習のコード
# マージソート
import random
import unittest
LIMIT = 4
def insert_sort(inlist, begin, end):
for i in xrange(begin + 1, end):
@yasuharu519
yasuharu519 / DeadPixels.cpp
Last active December 12, 2015 03:38
Facebook Hacker Cup Rount1 #3 DeadPixels
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<long,long> Coordinate;
int getValue(map<Coordinate, long>_map, long x, long y){
@yasuharu519
yasuharu519 / Security.py
Created February 4, 2013 17:30
Facebook Hacker Cup Rount1 #2 Security
import sys
def compare(chunk_key1, chunk_key2):
answer = []
for key1, key2 in zip(chunk_key1, chunk_key2):
for c1, c2 in zip(key1, key2):
if c1 == '?' and c2 == '?':
answer.append('a')
elif c1 == '?':
answer.append(c2)
@yasuharu519
yasuharu519 / CardGame.cpp
Last active December 12, 2015 03:38
Facebook Hacker Cup Rount1 #1 CardGame
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define MODULO 1000000007
long factorial(long k)
{
@yasuharu519
yasuharu519 / 3_FindTheMin.cpp
Created January 29, 2013 14:33
QualificationRound No.3 Find the Min
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
using namespace std;
long getNext(long a, long b, long c, long r){
return (b * a + c) % r;
}
@yasuharu519
yasuharu519 / 2_BalancedSmileys.py
Created January 29, 2013 14:32
QualificationRound No.2 Balanced Smileys
import sys
import re
from string import ascii_lowercase
ascii_lowercase = ascii_lowercase + " :"
def evaluate(string):
"""
>>> evaluate(":((")
False
@yasuharu519
yasuharu519 / 1_BeautifulStrings.py
Created January 29, 2013 14:31
QualificationRound No.1 Beautiful strings
import sys
from string import ascii_lowercase
def getCharFrequency(string):
result = dict()
for c in string:
lowerC = c.lower()
if lowerC in ascii_lowercase:
if not result.has_key(lowerC):
result[lowerC] = 1
@yasuharu519
yasuharu519 / CodeIQChallengeID171.py
Created January 18, 2013 06:46
The Essence of Programming 結城 浩さんからのアルゴリズムの問題 https://codeiq.jp/ace/yuki_hiroshi/q171
import sys
class NicknameSets(object):
def __init__(self):
self.nickKinds = list()
def add(self, a, b):
for k in self.nickKinds:
if a in k or b in k:
k.add(a)