Skip to content

Instantly share code, notes, and snippets.

@twsm000
twsm000 / main.go
Created April 4, 2024 02:17
Advent of Code 2023 - Day Three - Part 1
package main
import (
"bufio"
"fmt"
"os"
"regexp"
)
var (
@twsm000
twsm000 / exercise-web-crawler.go
Last active March 18, 2022 22:30
Exercise from "A Tour of Go"
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and a slice of URLs found on that page.
Fetch(url string) (body string, urls []string, err error)
@twsm000
twsm000 / exercise-images.go
Created October 26, 2020 00:49
A Tour of Go - Exercise: Images
package main
import (
"image"
"image/color"
"golang.org/x/tour/pic"
)
type Image struct {
@twsm000
twsm000 / exercise-rot-reader.go
Created October 25, 2020 23:28
A Tour of Go - Exercise: rot13Reader
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
@twsm000
twsm000 / exercise-fibonacci-closure.go
Created October 21, 2020 04:32
A Tour of Go - Exercise: Fibonacci closure
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a, b, c := 0, 1, 1
return func() (result int) {
result = a
@twsm000
twsm000 / exercise-maps.go
Created October 21, 2020 04:29
A Tour of Go - Exercise: Maps
package main
import (
"strings"
"golang.org/x/tour/wc"
)
func WordCount(s string) (result map[string]int) {
result = make(map[string]int)
@twsm000
twsm000 / exercise-loops-and-functions.go
Created October 21, 2020 00:55
A Tour of Go - Exercise: Loops and Functions
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) (last float64) {
z := 1.0
for {