day20, modules state comparations
This commit is contained in:
@@ -27,6 +27,7 @@ type Signal struct {
|
||||
type Module interface {
|
||||
Receive(s Signal) []Signal
|
||||
Outputs() []string
|
||||
StateSnapshot() string
|
||||
}
|
||||
|
||||
// Modules
|
||||
@@ -71,6 +72,10 @@ func (ff *FlipFlop)String() string {
|
||||
return fmt.Sprintf("[flip-flop '%s' (on: %t) -> %s]", ff.Name, ff.IsOn, ff.OutputNames)
|
||||
}
|
||||
|
||||
func (ff *FlipFlop)StateSnapshot() string {
|
||||
return ff.String()
|
||||
}
|
||||
|
||||
func IsLineFlipFlop(line string) bool {
|
||||
return strings.HasPrefix(line, "%")
|
||||
}
|
||||
@@ -108,6 +113,9 @@ func (b *Broadcast)Outputs() []string {
|
||||
func (b *Broadcast)String() string {
|
||||
return fmt.Sprintf("[broadcast -> %+v]", b.OutputNames)
|
||||
}
|
||||
func (b *Broadcast)StateSnapshot() string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func IsLineBroadcast(line string) bool {
|
||||
return strings.HasPrefix(line, "broadcaster")
|
||||
@@ -174,6 +182,10 @@ func (c *Conjunction)String() string {
|
||||
return fmt.Sprintf("[conjunction '%s' -> %+v]", c.Name, c.OutputNames)
|
||||
}
|
||||
|
||||
func (c *Conjunction)StateSnapshot() string {
|
||||
return fmt.Sprintf("[conjunction '%s' -> %+v]", c.Name, c.MostRecentPulseFromInputIsHigh)
|
||||
}
|
||||
|
||||
func IsLineConjunction(line string) bool {
|
||||
return strings.HasPrefix(line, "&")
|
||||
}
|
||||
@@ -207,6 +219,10 @@ func (b *Button)String() string {
|
||||
return "[button]"
|
||||
}
|
||||
|
||||
func (b *Button)StateSnapshot() string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
type Output struct {}
|
||||
|
||||
func (o *Output)Receive(s Signal) []Signal {
|
||||
@@ -221,3 +237,7 @@ func (o *Output)Outputs() []string {
|
||||
func (o *Output)String() string {
|
||||
return "[output]"
|
||||
}
|
||||
|
||||
func (o *Output)StateSnapshot() string {
|
||||
return o.String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user