go_book_exercises

module
v0.0.0-...-ec09f47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2020 License: MIT

README

The Go Programming Language Book exercises

Since I'm a fan of buying books with exercises, tasks or projects I embarked in doing all the exercises of this cute language book.

All exercises were written, run and/or tested on a Linux x64 machine, but besides the cgo chapter (chapter 13), I don't think there's anything too OS/Arch dependant.

I would be remiss if I didn't link the book page

Contributions

Feel free to open an issue and/or PR in case you find something that's not quite right.

License

MIT

Directories

Path Synopsis
chapter1
dup1 command
dup2 command
dup3 command
echo1 command
echo2 command
echo3 command
exercise1_1 command
exercise1_10 command
exercise1_2 command
exercise1_3 command
exercise1_4 command
exercise1_5 command
exercise1_6 command
exercise1_7 command
exercise1_8 command
exercise1_9 command
fetch command
fetchall command
helloworld command
lissajous command
server1 command
server2 command
server3 command
chapter10
exercise10_1 command
exercise10_2
Define a generic archive file-reading function capable of reading ZIP files (archive/zip) and POSIX tar files (archive/tar).
Define a generic archive file-reading function capable of reading ZIP files (archive/zip) and POSIX tar files (archive/tar).
exercise10_4 command
Construct a tool that reports the set of all packages in the workspace that transitively depend on the packages specified by the arguments.
Construct a tool that reports the set of all packages in the workspace that transitively depend on the packages specified by the arguments.
jpeg command
The jpeg command reads a PNG image from stdin and writes it as a JPEG image to stdout
The jpeg command reads a PNG image from stdin and writes it as a JPEG image to stdout
chapter11
echo command
exercise11_1 command
Write tests for the charcount program in Section 4.3
Write tests for the charcount program in Section 4.3
exercise11_2 command
exercise11_4
Modify randomPalindrome to exercise IsPalindrome's handling of punctuation and spaces.
Modify randomPalindrome to exercise IsPalindrome's handling of punctuation and spaces.
exercise11_6 command
Write benchmarks to compare the PopCount implementation in section 2.6.23 with your solutions to exercise 2.4 and exercise 2.5.
Write benchmarks to compare the PopCount implementation in section 2.6.23 with your solutions to exercise 2.4 and exercise 2.5.
exercise11_7 command
chapter12
exercise12_1
Extend Display so that it can display maps whose keys are structs or arrays
Extend Display so that it can display maps whose keys are structs or arrays
exercise12_13
Modify the S-expression encoder (§12.4) and decoder (§12.6) so that they honr the sexpr:"..." field tag in a similar manner to encoding/json.
Modify the S-expression encoder (§12.4) and decoder (§12.6) so that they honr the sexpr:"..." field tag in a similar manner to encoding/json.
exercise12_2
Make display safe to use on cyclic data structures by bounding the number of steps it takes before abandoning the recursion.
Make display safe to use on cyclic data structures by bounding the number of steps it takes before abandoning the recursion.
exercise12_3
Implement the missing cases of the encode function.
Implement the missing cases of the encode function.
exercise12_4
Modify encode to pretty-print the S-expression in the style shown above
Modify encode to pretty-print the S-expression in the style shown above
exercise12_5
Adapt encode to emit JSON instead of S-expressions.
Adapt encode to emit JSON instead of S-expressions.
exercise12_6
Adapt encode so that as an optimization, it does not encode a field whose value is the zero value of its type
Adapt encode so that as an optimization, it does not encode a field whose value is the zero value of its type
exercise12_8
Exercise 12.8: The sexpr.Unmarshal function, like json.Marshal, requires the complete input in a byte slice before it can begin decoding.
Exercise 12.8: The sexpr.Unmarshal function, like json.Marshal, requires the complete input in a byte slice before it can begin decoding.
search command
chapter13
bzipper command
exercise13_3
Use sync.Mutex to make bzip2.writer safe for concurrent use by multiple goroutines
Use sync.Mutex to make bzip2.writer safe for concurrent use by multiple goroutines
unsafeptr command
chapter2
boiling command
cf command
echo4 command
exercise2_2 command
exercise2_3 command
exercise2_4 command
exercise2_5 command
ftoc command
chapter3
basename command
comma command
exercise3_1 command
If the function f returns a non-finite float64 value, the SVG file will contain invalid <polygon> elements (althought many SVG renderers handle this gracefully).
If the function f returns a non-finite float64 value, the SVG file will contain invalid <polygon> elements (althought many SVG renderers handle this gracefully).
exercise3_10 command
Write a non-recursive version of comma, using bytes.Buffer instead of string concatenation.
Write a non-recursive version of comma, using bytes.Buffer instead of string concatenation.
exercise3_11 command
Exercise 3.11: Enhance comma so that it deals correctly with floating-point numbers and an optional sign.
Exercise 3.11: Enhance comma so that it deals correctly with floating-point numbers and an optional sign.
exercise3_12 command
exercise3_13 command
exercise3_2 command
exercise3_3 command
Color each polygon based on its height, so that the peaks are colored red (#ff0000) and the valleys blue (#0000ff)
Color each polygon based on its height, so that the peaks are colored red (#ff0000) and the valleys blue (#0000ff)
exercise3_4 command
Following the appraoch of the Lissajous example in Section 1.7, construct a web server that computes surfaces and writes SVG data to the client.
Following the appraoch of the Lissajous example in Section 1.7, construct a web server that computes surfaces and writes SVG data to the client.
exercise3_5 command
Implement full color Mandlebrot set using the fucntion image.NEwRGBA and the ttype color.RGBA or color.YCbCr
Implement full color Mandlebrot set using the fucntion image.NEwRGBA and the ttype color.RGBA or color.YCbCr
exercise3_6 command
Implement full color Mandlebrot set using the fucntion image.NEwRGBA and the ttype color.RGBA or color.YCbCr
Implement full color Mandlebrot set using the fucntion image.NEwRGBA and the ttype color.RGBA or color.YCbCr
exercise3_7 command
Another simple fractal uses Newton's method to find complex solution to a function such as z^4 - 1.
Another simple fractal uses Newton's method to find complex solution to a function such as z^4 - 1.
exercise3_8 command
exercise3_9 command
mandelbrot command
surface command
chapter4
append command
charcount command
dedup command
embed command
exercise4_1 command
exercise4_10 command
exercise4_12 command
exercise4_13 command
The JSON-based websiervce of the Open Movie Database let's you search https://omdbapi.com/ for a movie by name and downlaod ists poster image.
The JSON-based websiervce of the Open Movie Database let's you search https://omdbapi.com/ for a movie by name and downlaod ists poster image.
exercise4_14 command
Create a web server that queries GitHub once and then allows navigation of the list of bug reports, milestones and users.
Create a web server that queries GitHub once and then allows navigation of the list of bug reports, milestones and users.
exercise4_2 command
exercise4_3 command
exercise4_4 command
exercise4_5 command
exercise4_6 command
Write an in-place function that squashes each run of adjacent Unicode spaces (see unicode.IsSpace) in a UTF-8-encoded []byte slice into a single ASCII space
Write an in-place function that squashes each run of adjacent Unicode spaces (see unicode.IsSpace) in a UTF-8-encoded []byte slice into a single ASCII space
exercise4_7 command
exercise4_8 command
exercise4_9 command
graph command
issues command
issueshtml command
issuesreport command
nonempty command
remove command
rev command
sha256 command
treesort command
chapter5
defer1 command
defer2 command
exercise5_1 command
exercise5_10 command
exercise5_11 command
The instructor of the linear algebra course decids that calculus is now a prerequisite.
The instructor of the linear algebra course decids that calculus is now a prerequisite.
exercise5_12 command
exercise5_13 command
exercise5_14 command
exercise5_15 command
Write variadic funcions max and minx, analogous to sum.
Write variadic funcions max and minx, analogous to sum.
exercise5_16 command
Write a variadic version of strings.Join
Write a variadic version of strings.Join
exercise5_17 command
exercise5_18 command
Without changing its behaviour rewrite the fetch function to use defer to close the writable file.
Without changing its behaviour rewrite the fetch function to use defer to close the writable file.
exercise5_19 command
Use panic and recover to write a function that contains no return statement yet return a non-zero value.
Use panic and recover to write a function that contains no return statement yet return a non-zero value.
exercise5_2 command
exercise5_3 command
Write a function to print the contents of all text nodes in an HTML document tree.
Write a function to print the contents of all text nodes in an HTML document tree.
exercise5_4 command
exercise5_5 command
Implement countWordsAndImages (see exercise 4.9 for word-splitting)
Implement countWordsAndImages (see exercise 4.9 for word-splitting)
exercise5_6 command
exercise5_7 command
Develop startElement and endElement into a general HTML pretty printer.
Develop startElement and endElement into a general HTML pretty printer.
exercise5_8 command
Modify forEachNode so that the pre and post functions return a boolean result indicating whether to continue the traversal.
Modify forEachNode so that the pre and post functions return a boolean result indicating whether to continue the traversal.
exercise5_9 command
Write a function expand(s string, f func(string) string) string that replaces each substring "$foo" withing s by the text returned by f("foo").
Write a function expand(s string, f func(string) string) string that replaces each substring "$foo" withing s by the text returned by f("foo").
fetch command
findlinks1 command
findlinks2 command
findlinks3 command
outline command
outline2 command
squares command
title1 command
title2 command
title3 command
toposort command
trace command
chapter6
exercise6_1 command
Implement these additional methods: func (*IntSet) Len() int // return the number of elements func (*IntSet) Remove(x int) // remove x from the set func (*IntSet) Clear() // remove all elements from the set func (*IntSet) Copy() *IntSet // return a copy of the set
Implement these additional methods: func (*IntSet) Len() int // return the number of elements func (*IntSet) Remove(x int) // remove x from the set func (*IntSet) Clear() // remove all elements from the set func (*IntSet) Copy() *IntSet // return a copy of the set
exercise6_2 command
Define a variadic (*IntSet).AddAll(...int) method that allows a list of values to be added, such as s.AddAll(1, 2, 3)
Define a variadic (*IntSet).AddAll(...int) method that allows a list of values to be added, such as s.AddAll(1, 2, 3)
exercise6_3 command
(*IntSet).UnionWith computes the union of two sets unhsing |, the word-parallel bitwise OR operator.
(*IntSet).UnionWith computes the union of two sets unhsing |, the word-parallel bitwise OR operator.
exercise6_4 command
Add a method Elemsx that returns a slice containein the elements of the set, suitable for itrating over with a range loop.
Add a method Elemsx that returns a slice containein the elements of the set, suitable for itrating over with a range loop.
exercise6_5 command
The type of each word used by IntSet is uint64, but 64-bit airthmetic may be ineffictinetn on a 32-bit platform.
The type of each word used by IntSet is uint64, but 64-bit airthmetic may be ineffictinetn on a 32-bit platform.
intset command
urlvalues command
chapter7
bytecounter command
exercise7_1 command
exercise7_11 command
exercise7_12 command
Change the handler for /list ot print its output as an HTML table, not text You may find the html/template package useful.
Change the handler for /list ot print its output as an HTML table, not text You may find the html/template package useful.
exercise7_15 command
exercise7_16 command
exercise7_17 command
exercise7_18 command
Using the token-based decoder API, write a promgram that will read an arbitrary XML document and construct a tree of generic nodes that represents it.
Using the token-based decoder API, write a promgram that will read an arbitrary XML document and construct a tree of generic nodes that represents it.
exercise7_2 command
Write a function CountingWriter with the signature below that, given an io.Writer returns a new Writer that wraps the original, and a a pointer to an int64 variable that at any moment contains the number of bytes writen to the new Writer.
Write a function CountingWriter with the signature below that, given an io.Writer returns a new Writer that wraps the original, and a a pointer to an int64 variable that at any moment contains the number of bytes writen to the new Writer.
exercise7_3 command
exercise7_4 command
exercise7_5 command
The LimitReader function in the io package accepts an io.Reader r and a number of bytes n, and returns another Reader that reads from r but reports and end-of-file condition after n bytes.
The LimitReader function in the io package accepts an io.Reader r and a number of bytes n, and returns another Reader that reads from r but reports and end-of-file condition after n bytes.
exercise7_6 command
exercise7_8 command
exercise7_9 command
Use the html/template package to replace printTracks with a functions taht displays the tracks as an HTML table.
Use the html/template package to replace printTracks with a functions taht displays the tracks as an HTML table.
http1 command
http2 command
http3 command
http3a command
http4 command
sleep command
sorting command
surface command
tempflag command
xmlselect command
chapter8
chat command
clock1 command
Clock1 is a TCP server that periodically writes the time
Clock1 is a TCP server that periodically writes the time
clock2 command
Clock1 is a TCP server that periodically writes the time
Clock1 is a TCP server that periodically writes the time
countdown1 command
countdown2 command
countdown3 command
crawl1 command
crawl2 command
crawl3 command
du1 command
du2 command
du3 command
du4 command
exercise8_1/clock2 command
Modify clock2 to accept a port number, and write a program, clockwall, that acts as a client of several clock servers at once, reading the times from each one and displays the result in a table, akin to the wall of clocks seen in some business offices.
Modify clock2 to accept a port number, and write a program, clockwall, that acts as a client of several clock servers at once, reading the times from each one and displays the result in a table, akin to the wall of clocks seen in some business offices.
exercise8_1/clockwall command
Modify clock2 to accept a port number, and write a program, clockwall, that acts as a client of several clock servers at once, reading the times from each one and displays the result in a table, akin to the wall of clocks seen in some business offices.
Modify clock2 to accept a port number, and write a program, clockwall, that acts as a client of several clock servers at once, reading the times from each one and displays the result in a table, akin to the wall of clocks seen in some business offices.
exercise8_10 command
exercise8_11 command
exercise8_12 command
exercise8_13 command
exercise8_14 command
Change the chat server's network protocol so that each client provides its name on entering.
Change the chat server's network protocol so that each client provides its name on entering.
exercise8_15 command
Failure of any client program to read data in a timely manner ultimately causes all clients to get struck.
Failure of any client program to read data in a timely manner ultimately causes all clients to get struck.
exercise8_2 command
Implement a concurrent FTP sever.
Implement a concurrent FTP sever.
exercise8_3 command
exercise8_4 command
Modify the reverb2 server to use a sync.WaitGroup per connection to count the number of active echo goroutines.
Modify the reverb2 server to use a sync.WaitGroup per connection to count the number of active echo goroutines.
exercise8_5 command
exercise8_6 command
Add depth-limiting to the concurrent crawler.
Add depth-limiting to the concurrent crawler.
exercise8_7 command
exercise8_8 command
exercise8_9 command
netcat1 command
netcat2 command
netcat3 command
pipeline1 command
pipeline2 command
pipeline3 command
reverb1 command
reverb2 command
spinner command
thumbnail command
thumbnail2 command
thumbnail3 command
thumbnail4 command
thumbnail5 command
thumbnail6 command
chapter9
exercise9_2
Rewrite the PopCount example from Section 2.6.2 so that it initializes the lookup table using sync.ONe the first time it is needed.
Rewrite the PopCount example from Section 2.6.2 so that it initializes the lookup table using sync.ONe the first time it is needed.
exercise9_3
Extend the Func type and the (*Memo).Get method so that callers may provide an optional done channel through whicht hey can cancel the operation.
Extend the Func type and the (*Memo).Get method so that callers may provide an optional done channel through whicht hey can cancel the operation.
exercise9_4
Construct a pipeline that connects an arbitrary number of goroutines with channels.
Construct a pipeline that connects an arbitrary number of goroutines with channels.
exercise9_5 command
Write a program with two goroutines that send messages back and forth over two unbuffered channels in ping-pong fashion.
Write a program with two goroutines that send messages back and forth over two unbuffered channels in ping-pong fashion.
exercise9_6 command
memo1
Package memo provides a concurrency-unsafe memorization of a function of type Func.
Package memo provides a concurrency-unsafe memorization of a function of type Func.
memo2
Package memo provides a concurrency-unsafe memorization of a function of type Func.
Package memo provides a concurrency-unsafe memorization of a function of type Func.
memo3
Package memo provides a concurrency-unsafe memorization of a function of type Func.
Package memo provides a concurrency-unsafe memorization of a function of type Func.
memo4
Package memo provides a concurrency-unsafe memorization of a function of type Func.
Package memo provides a concurrency-unsafe memorization of a function of type Func.
memo5
Package memo provides a concurrency-unsafe memorization of a function of type Func.
Package memo provides a concurrency-unsafe memorization of a function of type Func.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL