Sha256: 6ff861a1807ca2c9f75a00b0fc6e74a07099618e6a412c01ebf6b4610eafb65b

Contents?: true

Size: 425 Bytes

Versions: 274

Compression:

Stored size: 425 Bytes

Contents

package octal

import (
	"fmt"
)

const testVersion = 1

func ParseOctal(octal string) (int64, error) {
	num := int64(0)
	for _, digit := range octal {
		// if any digits aren't octal digits (0-7), return 0
		if digit < '0' || digit > '7' {
			return 0, fmt.Errorf("unexpected rune '%c'", digit)
		}
		// multiply the current number by 8 (left shift) and add the digit
		num = num<<3 + int64(digit-'0')
	}
	return num, nil
}

Version data entries

274 entries across 274 versions & 1 rubygems

Version Path
trackler-2.2.0.3 tracks/go/exercises/octal/example.go
trackler-2.2.0.2 tracks/go/exercises/octal/example.go
trackler-2.2.0.1 tracks/go/exercises/octal/example.go
trackler-2.2.0.0 tracks/go/exercises/octal/example.go
trackler-2.1.0.55 tracks/go/exercises/octal/example.go
trackler-2.1.0.54 tracks/go/exercises/octal/example.go
trackler-2.1.0.53 tracks/go/exercises/octal/example.go
trackler-2.1.0.52 tracks/go/exercises/octal/example.go
trackler-2.1.0.51 tracks/go/exercises/octal/example.go
trackler-2.1.0.50 tracks/go/exercises/octal/example.go
trackler-2.1.0.49 tracks/go/exercises/octal/example.go
trackler-2.1.0.48 tracks/go/exercises/octal/example.go
trackler-2.1.0.47 tracks/go/exercises/octal/example.go
trackler-2.1.0.46 tracks/go/exercises/octal/example.go
trackler-2.1.0.45 tracks/go/exercises/octal/example.go
trackler-2.1.0.44 tracks/go/exercises/octal/example.go
trackler-2.1.0.43 tracks/go/exercises/octal/example.go
trackler-2.1.0.42 tracks/go/exercises/octal/example.go
trackler-2.1.0.41 tracks/go/exercises/octal/example.go
trackler-2.1.0.40 tracks/go/exercises/octal/example.go