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
chapter10
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
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
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
exercise11_1
Write tests for the charcount program in Section 4.3
Write tests for the charcount program in Section 4.3
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
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.
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.
chapter13
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
chapter2
cf
chapter3
exercise3_1
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
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
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_3
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
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
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
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
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.
chapter4
exercise4_13
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
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_6
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
rev
chapter5
exercise5_11
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_15
Write variadic funcions max and minx, analogous to sum.
Write variadic funcions max and minx, analogous to sum.
exercise5_16
Write a variadic version of strings.Join
Write a variadic version of strings.Join
exercise5_18
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
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_3
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_5
Implement countWordsAndImages (see exercise 4.9 for word-splitting)
Implement countWordsAndImages (see exercise 4.9 for word-splitting)
exercise5_7
Develop startElement and endElement into a general HTML pretty printer.
Develop startElement and endElement into a general HTML pretty printer.
exercise5_8
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
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").
chapter6
exercise6_1
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
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
(*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
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
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.
chapter7
exercise7_12
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_18
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
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_5
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_9
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.
chapter8
clock1
Clock1 is a TCP server that periodically writes the time
Clock1 is a TCP server that periodically writes the time
clock2
Clock1 is a TCP server that periodically writes the time
Clock1 is a TCP server that periodically writes the time
du1
du2
du3
du4
exercise8_1/clock2
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
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_14
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
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
Implement a concurrent FTP sever.
Implement a concurrent FTP sever.
exercise8_4
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_6
Add depth-limiting to the concurrent crawler.
Add depth-limiting to the concurrent crawler.
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
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.
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