Starting to make library out of intcode processor (from day 2)

This commit is contained in:
Brian Buller 2019-12-04 09:02:34 -06:00
parent 4537c3b913
commit ed78ac855a
3 changed files with 27 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"../intcode-processor"
"bufio" "bufio"
"fmt" "fmt"
"log" "log"
@ -11,6 +12,7 @@ import (
func main() { func main() {
inp := StdinToString() inp := StdinToString()
i := intcode.Program
f := func(c rune) bool { f := func(c rune) bool {
return c == ',' return c == ','
} }
@ -18,7 +20,9 @@ func main() {
for _, v := range strings.FieldsFunc(inp, f) { for _, v := range strings.FieldsFunc(inp, f) {
prog = append(prog, Atoi(v)) prog = append(prog, Atoi(v))
} }
part2(prog) i := intcode.NewProgram(prog)
i.PrintCode()
//part2(prog)
} }
func part1(prog []int) { func part1(prog []int) {

View File

@ -0,0 +1,3 @@
module intcode
go 1.13

View File

@ -0,0 +1,19 @@
package intcode
import "fmt"
type Program struct {
code []int
ptr int
}
func NewProgram(prog []int) *Program {
p := new(Program)
p.code = make([]int, len(prog))
copy(p.code, prog)
return p
}
func (p *Program) PrintCode() {
fmt.Println(code)
}