Sha256: 4aabe96b14829dd746315bca95a24c27679e8400c2c4f558f6bcdaaf9f7f6051

Contents?: true

Size: 974 Bytes

Versions: 153

Compression:

Stored size: 974 Bytes

Contents

package say

const testVersion = 1

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

153 entries across 153 versions & 1 rubygems

Version Path
trackler-2.0.8.34 tracks/go/exercises/say/example.go
trackler-2.0.8.33 tracks/go/exercises/say/example.go
trackler-2.0.8.32 tracks/go/exercises/say/example.go
trackler-2.0.8.31 tracks/go/exercises/say/example.go
trackler-2.0.8.30 tracks/go/exercises/say/example.go
trackler-2.0.8.29 tracks/go/exercises/say/example.go
trackler-2.0.8.28 tracks/go/exercises/say/example.go
trackler-2.0.8.27 tracks/go/exercises/say/example.go
trackler-2.0.8.26 tracks/go/exercises/say/example.go
trackler-2.0.8.24 tracks/go/exercises/say/example.go
trackler-2.0.8.23 tracks/go/exercises/say/example.go
trackler-2.0.8.22 tracks/go/exercises/say/example.go
trackler-2.0.8.21 tracks/go/exercises/say/example.go