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 / c.py
Created August 21, 2012 18:56
ACM-ICPC Thailand Central 2012
from fractions import Fraction
from math import factorial
from operator import mul
from functools import reduce
def product(member):
return reduce(mul, member)
def repile(minimum, remain_piles, remain_dishes, case, stack=[]):
@neizod
neizod / c.hs
Created August 24, 2012 23:17
power set of subtraction of n where every element in each subset are greater than m.
repile r 1 d m s = if d >= head s then (d:s):r else r
repile r p d m s = do
if d > m
then repile (repile r (p-1) (d-m) m (m:s)) p d (m+1) s
else r
mkpile r 0 d m = mkpile r (d `div` m) d m
mkpile r p d m = do
if p > 1
then mkpile (repile r p d m []) (p-1) d m
@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>
@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
-- 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 / 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
@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 / 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 / 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 / enlightened-32x24.txt
Created March 29, 2013 03:57
ascii ingress logo
^.
Xx\.
X| x\.
X| ^x)
X| / ._
<X\. / x\.
^ X\ x\._
_..xxXXxx.__ ^x%%/^
./x/ ^\x..
~^^^ _. ._ ^^