diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2026-04-02 10:59:18 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2026-04-02 10:59:18 -0400 |
| commit | 8bd3d98cb03e0be26084ca94224b8ef4e1e15a71 (patch) | |
| tree | 9ff7b5ab23901f4a9934ee4e32c5a0c253632c5c /fmt.go | |
| parent | 1343ef5b4c922ed512ae64a86d22970ebff7155d (diff) | |
| download | markov-8bd3d98cb03e0be26084ca94224b8ef4e1e15a71.zip | |
Diffstat (limited to 'fmt.go')
| -rw-r--r-- | fmt.go | 34 |
1 files changed, 0 insertions, 34 deletions
@@ -1,34 +0,0 @@ -// This program wraps its input into short lines. It is based on fmt.awk from "The -// Practice of Programming" by Brian Kernighan and Rob Pike (pp. 229). -package main - -import ( - "bufio" - "fmt" - "os" -) - -const maxWidth = 80 // maximum number of characters per line - -func main() { - input := bufio.NewScanner(os.Stdin) - input.Split(bufio.ScanWords) - width := 0 - for input.Scan() { - word := input.Text() - - if width+1+len(word) > maxWidth { - fmt.Println() - width = 0 - } - - if width == 0 { - fmt.Print(word) - width += len(word) - } else { - fmt.Printf(" %s", word) - width += 1 + len(word) - } - } - fmt.Println() -} |