mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-24 03:10:47 +00:00
32 lines
529 B
Go
32 lines
529 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"log"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
// readlines reads lines from stdin.
|
||
|
// it returns them as an array of strings
|
||
|
func readlines() []string {
|
||
|
lines := []string{}
|
||
|
|
||
|
scanner := bufio.NewScanner(os.Stdin)
|
||
|
for scanner.Scan() {
|
||
|
lines = append(lines, scanner.Text())
|
||
|
}
|
||
|
|
||
|
if err := scanner.Err(); err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
return lines
|
||
|
}
|
||
|
|
||
|
// replaceAtIndex replaces a character in a string at index i
|
||
|
func replaceAtIndex(in string, r rune, i int) string {
|
||
|
out := []rune(in)
|
||
|
out[i] = r
|
||
|
return string(out)
|
||
|
}
|