Day 5, part 2.
This commit is contained in:
@ -3,9 +3,10 @@ package polymer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func ApplyReactions(data []byte) string {
|
||||
func ApplyReactions(data []byte) []byte {
|
||||
result := data
|
||||
changed := true
|
||||
|
||||
@ -13,7 +14,7 @@ func ApplyReactions(data []byte) string {
|
||||
result, changed = React(result)
|
||||
}
|
||||
|
||||
return string(result)
|
||||
return result
|
||||
}
|
||||
|
||||
// React finds substrings of the form "xX" or "Xx" and removes them, returning
|
||||
@ -40,3 +41,14 @@ func React(data []byte) ([]byte, bool) {
|
||||
// No changes possible.
|
||||
return result.Bytes(), changed
|
||||
}
|
||||
|
||||
// StripElement removes all instances of letter or its upper-case counterpart
|
||||
// from the input.
|
||||
func StripElement(data []byte, strip rune) []byte {
|
||||
return bytes.Map(func(r rune) rune {
|
||||
if r == strip || r == unicode.ToUpper(strip) {
|
||||
return -1
|
||||
}
|
||||
return r
|
||||
}, data)
|
||||
}
|
||||
|
Reference in New Issue
Block a user