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.2.1.56 tracks/go/exercises/say/example.go
trackler-2.2.1.55 tracks/go/exercises/say/example.go
trackler-2.2.1.54 tracks/go/exercises/say/example.go
trackler-2.2.1.53 tracks/go/exercises/say/example.go
trackler-2.2.1.52 tracks/go/exercises/say/example.go
trackler-2.2.1.51 tracks/go/exercises/say/example.go
trackler-2.2.1.50 tracks/go/exercises/say/example.go
trackler-2.2.1.49 tracks/go/exercises/say/example.go
trackler-2.2.1.48 tracks/go/exercises/say/example.go
trackler-2.2.1.47 tracks/go/exercises/say/example.go
trackler-2.2.1.46 tracks/go/exercises/say/example.go
trackler-2.2.1.45 tracks/go/exercises/say/example.go
trackler-2.2.1.44 tracks/go/exercises/say/example.go
trackler-2.2.1.43 tracks/go/exercises/say/example.go
trackler-2.2.1.42 tracks/go/exercises/say/example.go
trackler-2.2.1.41 tracks/go/exercises/say/example.go
trackler-2.2.1.40 tracks/go/exercises/say/example.go
trackler-2.2.1.39 tracks/go/exercises/say/example.go
trackler-2.2.1.38 tracks/go/exercises/say/example.go
trackler-2.2.1.37 tracks/go/exercises/say/example.go