Skip to content

Instantly share code, notes, and snippets.

View neizod's full-sized avatar
📚
phd completed, seeking my new goal in life

Nattawut Phetmak neizod

📚
phd completed, seeking my new goal in life
View GitHub Profile
from itertools import cycle, izip
k, l, m, n, d = [int(raw_input()) for _ in range(5)]
dragons = [cycle([False] * (i-1) + [True]) for i in {k, l, m, n}]
print sum(any(next(izip(*dragons))) for _ in xrange(d))
@neizod
neizod / google.txt
Last active December 16, 2015 05:19
palindrome
This file has been truncated, but you can view the full file.
1
2
3
11
22
101
111
121
202
212
@neizod
neizod / a.py
Created April 27, 2013 03:41
codejam 1a
def sqrt(n):
if n == 0:
return 0
a, b = divmod(n.bit_length(), 2)
x = 2 ** (a + b)
while True:
y = x + n // x
y //= 2
if y >= x:
return x
@neizod
neizod / perceptron.hs
Last active December 19, 2015 08:39
Simple perceptron train in Haskell.
type Vector = (Double, Double)
dotV :: Vector -> Vector -> Double
dotV (x, y) (u, v) = x * u + y * v
addV :: Vector -> Vector -> Vector
addV (x, y) (u, v) = (x + u, y + v)
@neizod
neizod / freq.html
Created March 29, 2014 17:35
[quick-dirty] html+js hack for cracking the substitution encryption.
<h3>encrypted sentence</h3>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<input name="text" size="40" />
<button id="mk">make</button>
<hr />
<h3>decrypted sentence</h3>
<div id="box"></div>
<hr />
@neizod
neizod / bubble.cpp
Last active August 29, 2015 14:06
Sorting Algorithms
#include <iostream>
using namespace std;
int arr[] = {2,5,3,9,1,0,7,4,8,6};
void show(int i=-1) {
for (int k=0; k<10; k++) {
if (i-1 == k) cout << "\x1b[37;1m";
if (i == k) cout << "\x1b[31;1m";
cout << arr[k];
@neizod
neizod / kmeans.py
Last active August 29, 2015 14:07
k-means clustering.
#!/usr/bin/env python3
import sys
from itertools import count
class Point(object):
def __init__(self, pp):
self.x, self.y = pp
#!/usr/bin/env python3
from numpy import matrix, zeros
class RandomWalk(object):
limpow = 10**9
offset = [(0,-1), (0,1), (-1,0), (1,0)]
@neizod
neizod / it.ipynb
Created May 11, 2015 00:26
test nbviewer
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Keybase proof

I hereby claim:

  • I am neizod on github.
  • I am neizod (https://keybase.io/neizod) on keybase.
  • I have a public key whose fingerprint is 48AB A6A9 A002 DCD8 6E24 DFB0 0E27 2831 8C9B 4947

To claim this, I am signing this object: