Sha256: f7ea2b0eee4fe1a08e002054c73ce21c0a50c7495e046b71449f7b8d9ac8542a

Contents?: true

Size: 951 Bytes

Versions: 121

Compression:

Stored size: 951 Bytes

Contents

package say

var small = []string{"zero", "one", "two", "three", "four", "five", "six",
	"seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen",
	"fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}
var tens = []string{"ones", "ten", "twenty", "thirty", "forty",
	"fifty", "sixty", "seventy", "eighty", "ninety"}
var scale = []string{"thousand", "million", "billion",
	"trillion", "quadrillion", "quintillion"}

func Say(n uint64) string {
	switch {
	case n < 20:
		return small[n]
	case n < 100:
		t := tens[n/10]
		s := n % 10
		if s > 0 {
			t += "-" + small[s]
		}
		return t
	case n < 1000:
		h := small[n/100] + " hundred"
		s := n % 100
		if s > 0 {
			h += " " + Say(s)
		}
		return h
	}
	sx := ""
	if p := n % 1000; p > 0 {
		sx = Say(p)
	}
	for i := 0; n >= 1000; i++ {
		n /= 1000
		if p := n % 1000; p > 0 {
			ix := Say(p) + " " + scale[i]
			if sx > "" {
				ix += " " + sx
			}
			sx = ix
		}
	}
	return sx
}

Version data entries

121 entries across 121 versions & 1 rubygems

Version Path
trackler-2.0.8.20 tracks/go/exercises/say/example.go
trackler-2.0.8.19 tracks/go/exercises/say/example.go
trackler-2.0.8.18 tracks/go/exercises/say/example.go
trackler-2.0.8.17 tracks/go/exercises/say/example.go
trackler-2.0.8.16 tracks/go/exercises/say/example.go
trackler-2.0.8.15 tracks/go/exercises/say/example.go
trackler-2.0.8.14 tracks/go/exercises/say/example.go
trackler-2.0.8.13 tracks/go/exercises/say/example.go
trackler-2.0.8.12 tracks/go/exercises/say/example.go
trackler-2.0.8.11 tracks/go/exercises/say/example.go
trackler-2.0.8.10 tracks/go/exercises/say/example.go
trackler-2.0.8.9 tracks/go/exercises/say/example.go
trackler-2.0.8.8 tracks/go/exercises/say/example.go
trackler-2.0.8.7 tracks/go/exercises/say/example.go
trackler-2.0.8.6 tracks/go/exercises/say/example.go
trackler-2.0.8.5 tracks/go/exercises/say/example.go
trackler-2.0.8.4 tracks/go/exercises/say/example.go
trackler-2.0.8.3 tracks/go/exercises/say/example.go
trackler-2.0.8.2 tracks/go/exercises/say/example.go
trackler-2.0.8.1 tracks/go/exercises/say/example.go