~smlavine/mazesolver

bb860e471828499f79efb1627f8da0c38772a98d — Sebastian LaVine 2 years ago d60cd42
Count density of ones and zeroes
1 files changed, 29 insertions(+), 2 deletions(-)

M mazesolver.go
M mazesolver.go => mazesolver.go +29 -2
@@ 1,6 1,33 @@
package main

import (
	"bufio"
	"fmt"
	"os"
)

func StdinZeroesAndOnes() (zeroes uint, ones uint) {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Split(bufio.ScanWords)

	for scanner.Scan() {
		switch scanner.Text() {
		case "0":
			zeroes++
		case "1":
			ones++
		}
	}

	return zeroes, ones
}

func main() {
	// XXX: placeholder
	print("Hello, mazesolver\n")
	zeroes, ones := StdinZeroesAndOnes()

	sumdec := float64(zeroes + ones)

	fmt.Printf("0s: %d\n1s: %d\n0s ratio: %.2f\n1s ratio: %.2f\n",
		zeroes, ones, float64(zeroes)/sumdec, float64(ones)/sumdec)
}