- syntax: เขียนยังไงให้ computer เข้าใจเรา?
- semantics: ภาษาที่เราเขียนมันมีขั้นตอนการทำงานยังไง?
- idioms: ปรัญชาเบื้องหลังภาษานั้นๆ
- เช่นภาษา python มีปรัชญาว่า มันควรมีเพียงวิธีเดียว (ที่ดีที่สุด) ในการเขียนโปรแกรมให้ทำงานอยากเดียวกัน (เพื่อให้ programmer สามารถอ่าน code คนอื่นได้ง่าย)
- ส่วนภาษา ruby มีปรัชญาตรงนี้กลับกัน คือจะเขียนยังไงก็ได้ให้มันทำงานได้ (programmer จะสนุกกับการเขียนโปรแกรม... แต่ programmer คนอื่นมาอ่านรู้เรื่องหรือเปล่าก็อีกเรื่อง)
- libraries: code ที่คนอื่นเขียนไว้ให้ใช้
- tools: เครื่องมือช่วยสร้างโปรแกรมในภาษานั้นๆ เช่น repl, debugger, ide
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 | |
2 | |
3 | |
11 | |
22 | |
101 | |
111 | |
121 | |
202 | |
212 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |