Skip to content

Instantly share code, notes, and snippets.

View Pygmalion69's full-sized avatar

Serge Helfrich Pygmalion69

View GitHub Profile
/* Govern ancient Sumeria. Heavily modified by Mike Arnautov 1975.
* Converted from Basic to PR1ME Fortran (mode 32R) MLA 1979.
* Rev.19.1, GGR version 14 Oct 83. MLA
* Converted to ANSI C December 2001. MLA
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
@Pygmalion69
Pygmalion69 / exercise-slices.go
Created February 28, 2020 14:27
A Tour of Go - Exercise: Slices
// https://tour.golang.org/moretypes/18
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy)
for y := range pic {
pic[y] = make([]uint8, dx)
for x := range pic[y] {
@Pygmalion69
Pygmalion69 / exercise-maps.go
Created February 28, 2020 15:31
A Tour of Go - Exercise: Maps
// https://tour.golang.org/moretypes/23
package main
import (
"strings"
"golang.org/x/tour/wc"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
@Pygmalion69
Pygmalion69 / exercise-fibonacci-closure.go
Last active February 28, 2020 18:26
A Tour of Go - Exercise: Fibonacci closure
// https://tour.golang.org/moretypes/26
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a, b := 1, 0
return func() int {
@Pygmalion69
Pygmalion69 / exercise-stringer.go
Created February 29, 2020 14:13
A Tour of Go - Exercise: Stringers
// https://tour.golang.org/methods/18
package main
import "fmt"
type IPAddr [4]byte
func (ip IPAddr) String() string {
return fmt.Sprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])
}
@Pygmalion69
Pygmalion69 / exercise-errors.go
Last active February 29, 2020 14:45
A Tour of Go - Exercise: Errors
// https://tour.golang.org/methods/20
package main
import (
"fmt"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
@Pygmalion69
Pygmalion69 / exercise-reader.go
Created February 29, 2020 16:08
A Tour of Go - Exercise: Reader
// https://tour.golang.org/methods/22
package main
import "golang.org/x/tour/reader"
type MyReader struct{}
func (r MyReader) Read(b []byte) (int, error) {
for i := range b {
b[i] = 65