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
@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 / 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
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 / LICENSE.txt
Last active December 14, 2015 04:39 — forked from Python1Liners/LICENSE.txt
Happy Valentine's Day
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2013 Nattawut Phetmak <http://about.me/neizod>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@neizod
neizod / week1.md
Last active December 11, 2015 09:59
ML, Racket, Ruby Lecture @ Cousera

เมื่อพูดถึงภาษาคอมพิวเตอร์

  • syntax: เขียนยังไงให้ computer เข้าใจเรา?
  • semantics: ภาษาที่เราเขียนมันมีขั้นตอนการทำงานยังไง?
  • idioms: ปรัญชาเบื้องหลังภาษานั้นๆ
    • เช่นภาษา python มีปรัชญาว่า มันควรมีเพียงวิธีเดียว (ที่ดีที่สุด) ในการเขียนโปรแกรมให้ทำงานอยากเดียวกัน (เพื่อให้ programmer สามารถอ่าน code คนอื่นได้ง่าย)
    • ส่วนภาษา ruby มีปรัชญาตรงนี้กลับกัน คือจะเขียนยังไงก็ได้ให้มันทำงานได้ (programmer จะสนุกกับการเขียนโปรแกรม... แต่ programmer คนอื่นมาอ่านรู้เรื่องหรือเปล่าก็อีกเรื่อง)
  • libraries: code ที่คนอื่นเขียนไว้ให้ใช้
  • tools: เครื่องมือช่วยสร้างโปรแกรมในภาษานั้นๆ เช่น repl, debugger, ide
@neizod
neizod / lecture.md
Created October 9, 2012 08:44
Mathematical Thinking

Logic

  • S => N
    • S is called antecedent.
    • S is sufficient for N.
    • N is necessary for S.
  • S <=> N
  • S is sufficient and necessary for N
@neizod
neizod / lecture.md
Created October 6, 2012 09:58
Learn to Program: The Fundamentals

Theory

Memory

There are 2 places of memory in Python program.

  • Heap: value of variables, functions recipe bind w/ memory address. e.g.
  • memory addr: x1 -> int: 42
-- groupIndices 5 [1..20] -> [[1,6,11,16],[2,7,12,17],[3,8,13,18],[4,9,14,19],[5,10,15,20]]
groupIndices n = map reverse . foldl (\a x -> [if length h /= length t then x:h else h | (h,t) <- zip a ((42:last a):init a)]) (take n $ repeat [])
@neizod
neizod / LICENSE.txt
Created September 3, 2012 00:40 — forked from Python1Liners/LICENSE.txt
Google Recruiting Board
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2012 Nattawut Phetmak <http://about.me/neizod>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@neizod
neizod / e-convergent.hs
Created September 2, 2012 19:45
Compute mathematical constant `e`.
e n = 1 + (foldr1 (\ a x -> a + 1 / x) $ take n [i ^ j | i <- [2,4..], j <- [0,0,1]])
-- sample:
-- e 1 -> 2.0
-- e 2 -> 3.0
-- e 6 -> 2.71875
-- e 100 -> 2.7182818284590455
-- see more:
-- <http://en.wikipedia.org/wiki/E_(mathematical_constant)#Representations>