Skip to content

Commit

Permalink
Optimized the Go version a little.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedrosa committed Nov 27, 2011
1 parent 41085a7 commit e37fe36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions luhny.go
Expand Up @@ -125,26 +125,28 @@ func sampleTest() {
func (lu Luhn) TapStdin() {
nRepeats := 1
if len(os.Args) > 1 { nRepeats, _ = strconv.Atoi(os.Args[1]) }
ios := bufio.NewReader(os.Stdin)
ios, _ := bufio.NewReaderSize(os.Stdin, 16384)
bw, _ := bufio.NewWriterSize(os.Stdout, 16384)
if nRepeats > 1 {
s, err := ios.ReadBytes('\n')
s, err := ios.ReadSlice('\n')
lines := []string{}
for err == nil {
lines = append(lines, string(s))
s, err = ios.ReadBytes('\n')
s, err = ios.ReadSlice('\n')
}
for i := 0; i < nRepeats; i++ {
for _, s := range lines {
fmt.Print(lu.Mask(s))
bw.WriteString(lu.Mask(s))
}
}
} else {
s, err := ios.ReadBytes('\n')
s, err := ios.ReadSlice('\n')
for err == nil {
fmt.Print(lu.Mask(string(s)))
s, err = ios.ReadBytes('\n')
bw.WriteString(lu.Mask(string(s)))
s, err = ios.ReadSlice('\n')
}
}
bw.Flush()
}

func main() {
Expand Down
4 changes: 2 additions & 2 deletions mask.sh
Expand Up @@ -3,5 +3,5 @@
# Call your program here instead of cat.
#cat
#./luhny.rb
./luhny.dart
#./goluhny
#./luhny.dart
./goluhny

0 comments on commit e37fe36

Please sign in to comment.