Starting to make library out of intcode processor (from day 2)
This commit is contained in:
parent
4537c3b913
commit
ed78ac855a
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"../intcode-processor"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
@ -11,6 +12,7 @@ import (
|
||||
|
||||
func main() {
|
||||
inp := StdinToString()
|
||||
i := intcode.Program
|
||||
f := func(c rune) bool {
|
||||
return c == ','
|
||||
}
|
||||
@ -18,7 +20,9 @@ func main() {
|
||||
for _, v := range strings.FieldsFunc(inp, f) {
|
||||
prog = append(prog, Atoi(v))
|
||||
}
|
||||
part2(prog)
|
||||
i := intcode.NewProgram(prog)
|
||||
i.PrintCode()
|
||||
//part2(prog)
|
||||
}
|
||||
|
||||
func part1(prog []int) {
|
||||
|
3
2019/intcode-processor/go.mod
Normal file
3
2019/intcode-processor/go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module intcode
|
||||
|
||||
go 1.13
|
19
2019/intcode-processor/processor.go
Normal file
19
2019/intcode-processor/processor.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user