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