Last active
September 22, 2016 05:02
-
-
Save daltonclaybrook/216973c9e70faba8407ca57516d1cdbd to your computer and use it in GitHub Desktop.
Punchcard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"strconv" | |
"strings" | |
) | |
type ScanError string | |
func (er *ScanError) Error() string { | |
return string(*er) | |
} | |
type Input struct { | |
alphabet string | |
lines []string | |
} | |
func getInput() (*Input, error) { | |
scanner := bufio.NewScanner(os.Stdin) | |
fmt.Print("Alphabet: ") | |
scanner.Scan() | |
alphaComponents := strings.Split(scanner.Text(), " ") | |
if len(alphaComponents) != 2 { | |
error := ScanError("Alphabet must have exactly two components.") | |
return nil, &error | |
} | |
alpha := alphaComponents[1] | |
fmt.Print("Line count: ") | |
scanner.Scan() | |
count, err := strconv.Atoi(scanner.Text()) | |
if err != nil { | |
return nil, err | |
} | |
lines := make([]string, count) | |
for i := 0; i < count; i++ { | |
fmt.Printf("Line %v: ", i+1) | |
scanner.Scan() | |
scan := scanner.Text() | |
lines[i] = scan | |
} | |
return &Input{alpha, lines}, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment