Go solution to Coding Challenges first challenge: build your own wc tool
goccwc % wc -c test.txt
342190 test.txt
goccwc % go run . -c test.txt
342190 test.txt
goccwc % wc -l test.txt
7145 test.txt
goccwc % go run . -l test.txt
7145 test.txt
% wc -w test.txt
58164 test.txt
goccwc % go run . -w test.txt
58164 test.txt
With the addition of some unit tests, which can be run with:
goccwc % go test .
ok ccwc
goccwc % wc -m test.txt
339292 test.txt
goccwc % go run . -m test.txt
339292 test.txt
% wc test.txt
7145 58164 342190 test.txt
goccwc % go run . test.txt
7145 58164 342190 test.txt
goccwc % cat test.txt | wc -l
7145
goccwc % cat test.txt | go run . -l
7145
goccwc % seq 1 300000 | xargs -Inone cat test.txt | wc
2143500000 17449200000 102657000000
goccwc % seq 1 300000 | xargs -Inone cat test.txt | go run .
2143500000 17449200000 102657000000
Both use < 3MB memory.