Skip to content

Instantly share code, notes, and snippets.

@benelog
Created November 3, 2011 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benelog/1335412 to your computer and use it in GitHub Desktop.
Save benelog/1335412 to your computer and use it in GitHub Desktop.
total block
total = 0
for i in range (1,11):
total += pow(i-1,2) + pow(i,2)
print total
@nephilim
Copy link

nephilim commented Nov 4, 2011

@codian 흐허~ :)

@nephilim
Copy link

nephilim commented Nov 4, 2011

fupfin님이 자기가 생각한 것도 짜라고 또 scala 코딩시켰어요. 어흐엉 사각형의 개수가 매 번 (4n- 4)개 씩 늘어난다는 것에 착안한 방법입니다.
ps. 미투에서 자신의 알고리즘이 너무 아름답다며 감탄하고 계시다는... ㅡ..ㅡ;

(List(1)/:(2 to 10)){ (sum, n) => (4*n - 4 + sum.head)::sum }.reduceLeft(_ + _) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment