Leanpub Header

Skip to main content

개미 수열을 푸는 10가지 방법

알아두면 피와 살이 될 프로그래밍 개념 10가지

1, 11, 21, 1211, ... 개미 수열(look-and-say sequence)을 코드로 옮겨본다. 여러분이 개미 수열의 1,000번째 줄, 혹은 10,000번째 줄을 출력할 수 있다면 이 책은 필요없을 것이다. 개미 수열을 놓고 C, Java, JavaScript, Go, Haskell 등 여러 언어를 넘나들며 정규표현식, 이터레이터, 코루틴, CSP 등 다양한 프로그래밍 개념들을 적용해본다.

Free With Membership

With Membership

Free!

$9.99

You pay

$9.99

Author earns

$7.99
$

...Or Buy With Credits!

You can get credits with a paid monthly or annual Reader Membership, or you can buy them here.
PDF
EPUB
WEB
518
Readers
108
Pages
6,751Words
About

About

About the Book

이 책은 심심풀이로 시작되었다. 하지만 어쩌다보니 2년에 걸쳐 갖가지 방법이 동원되었다. 단지 '개미 수열' 한 문제를 풀기위해 정규표현식, 이터레이터, 코루틴, CSP 등 다양한 프로그래밍 개념까지 적용되었다. 각 개념들이 왜 필요한지, 어떻게 동작하는지 두루 살펴본다.

개미 수열은 누구나 한번쯤 풀어봤을 법한 쉬운 문제다. 과연 그럴까? 개미 수열은 '읽고 말하기 수열(look-and-say sequence)'이라고도 알려져 있으며, 줄마다 30% 정도씩 길이가 늘어난다고 증명되었다. 기하급수적으로 커지기 때문에 대충 해서는 100번째 줄을 출력하기도 어렵다. 반면 Haskell 같은 언어에서는 큰 문제가 되지 않는다. 그 차이를 파고들어 Java나 JavaScript에서도 100번째 줄 혹은 백만번째 줄을 출력할 수 있게 프로그램을 고쳐나간다.

쉬운 문제를 통해 오래되었지만 여전히 유효한 개념들(코루틴(1958), 제너레이터(1975), CPS(1975), CSP(1978) 등)을 맛볼 수 있는 좋은 기회를 제공해 줄 것이다.

Share this book

Author

About the Author

한주영

10년 정도 개발 팀을 옆에서 도와주는 일만 했다. 코치나 해결사 역할은 흥미롭기는 하지만 공허할 때가 많다. 다시 개발자로 돌아가려고 하는데 떠난 시간이 길어서 그런지 쉽지 않다. 스타워즈 팬이다. 에피소드 7을 시작으로 시리즈가 부활하고 있어서 기쁘다. 책상에 앉아 있느라 가족들에게 소홀한 때가 많지만 그래도 패밀리맨이고 싶다.

현재 육아휴직 중이다. -- 2016년 겨울

다시 타이틀에 개발자를 붙이게 되었다. 육아 휴직을 잘 마쳤고, 두 번의 이직을 했다. 스타워즈는 마지막 에피소드를 앞두고 있다. -- 2018년 겨울

Contents

Table of Contents

머릿말

소스코드

1장 개미 수열 시작하기

  1. 읽고 말하기 수열
  2. 구글 랩스 적성 검사
  3. Java #0 - forString
  4. Haskell #0 - 리스트
  5. Java #1 - ant()next() 분리
  6. Wishful Thinking

2장 정규표현식

  1. 롭 파이크의 충고
  2. 반복 문자열 찾기
  3. JavaScript #0 - 정규표현식
  4. Java #2 - 정규표현식
  5. App-specific vs. General

3장 리스트 처리

  1. next()가 하는 일
  2. Java #3 - 리스트 처리
  3. 리스트 처리 함수들
  4. 연습. JavaScript 배열 처리하기
  5. 함수형 프로그래밍

4장 이터레이터

  1. 개미 수열의 특성
  2. 이터레이터와 이터러블
  3. 개미 수열과 이터레이터
  4. JavaScript #1 - 이터레이터
  5. 지연 리스트로서의 이터레이터
  6. 연습. Java 이터레이터 구현하기
  7. 이터레이터 구현 리뷰

5장 제너레이터

  1. JavaScript #2 - 제너레이터
  2. 연습. 제너레이터 group()map()
  3. Java #4 - 쓰레드를 이용한 제너레이터
  4. 이터레이터/제너레이터 리뷰
  5. 제너레이터 이해하기

6장 코루틴

  1. 코루틴 이해하기
  2. Go의 고루틴과 채널
  3. Go #0 - 채널과 고루틴
  4. 코루틴과 개미 수열
  5. C #0 - 코루틴
  6. C #1 - 매크로 푸!
  7. JavaScript #5 - 제너레이터 코루틴
  8. JavaScript #6 - js-csp
  9. 개미 수열 복잡도
  10. 코루틴 구현 리뷰

7장 CPS

  1. JavaScript #7 - CPS
  2. 연습. CPS 개미 수열(JavaScript) 완성하기
  3. Java #5 - CPS
  4. 파이프를 이용한 개미 수열
  5. CPS 구현 리뷰

8장 CSP와 인터프리터 패턴

  1. Go의 동시성 요소들
  2. CSP를 위한 미니 언어
  3. 핑퐁 예제
  4. CSP 표현법
  5. Java #6 - CSP 개미 수열
  6. 연습. 콜백 스타일로 applyN() 도움 함수 구현하기
  7. CSP 미니 언어 인터프리터
  8. CSP 인터프리터 리뷰
  9. 연습. CSP 미니 언어에 sleep() 추가하기
  10. 연습. CSP 미니 언어에 select() 추가하기

9장 지연 리스트

  1. Haskell의 리스트는 지연 리스트
  2. Haskell 코드 읽기
  3. 지연 리스트를 지원하는 언어들
  4. Java #7 - 지연 리스트
  5. 연습. Stream 클래스 Iterable 구현하기
  6. Java #8 - 지연 리스트 일반화
  7. 연습. iterate 구현하기
  8. head를 지연 연산하는가?
  9. 지연 리스트 리뷰

10장 리액티브 스트림

  1. 노드로 시작
  2. 배압
  3. 리액티브 스트림
  4. 연습. 쓰기 스트림을 Subscriber로 감싸기
  5. Java로 옮겨보기
  6. 정리

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub