day20: whelp.

This commit is contained in:
efim
2023-12-20 11:14:45 +00:00
parent 1e32ec0988
commit 57fdfb01cb
6 changed files with 272 additions and 17 deletions

View File

@@ -28,6 +28,7 @@ type Module interface {
Receive(s Signal) []Signal
Outputs() []string
StateSnapshot() string
MermaidFlow() string
}
// Modules
@@ -76,6 +77,14 @@ func (ff *FlipFlop)StateSnapshot() string {
return ff.String()
}
func (ff *FlipFlop)MermaidFlow() string {
result := "\n"
for _, toName := range ff.OutputNames {
result += fmt.Sprintf("%s --> %s\n", ff.Name, toName)
}
return result
}
func IsLineFlipFlop(line string) bool {
return strings.HasPrefix(line, "%")
}
@@ -117,6 +126,14 @@ func (b *Broadcast)StateSnapshot() string {
return b.String()
}
func (b *Broadcast)MermaidFlow() string {
result := "\n"
for _, toName := range b.OutputNames {
result += fmt.Sprintf("%s --> %s\n", "broadcast", toName)
}
return result
}
func IsLineBroadcast(line string) bool {
return strings.HasPrefix(line, "broadcaster")
}
@@ -186,6 +203,15 @@ func (c *Conjunction)StateSnapshot() string {
return fmt.Sprintf("[conjunction '%s' -> %+v]", c.Name, c.MostRecentPulseFromInputIsHigh)
}
func (c *Conjunction)MermaidFlow() string {
result := "\n"
for _, toName := range c.OutputNames {
result += fmt.Sprintf("%s --> %s\n", c.Name, toName)
}
return result
}
func IsLineConjunction(line string) bool {
return strings.HasPrefix(line, "&")
}
@@ -223,6 +249,10 @@ func (b *Button)StateSnapshot() string {
return b.String()
}
func (b *Button)MermaidFlow() string {
return "button --> broadcast\n"
}
type Output struct {}
func (o *Output)Receive(s Signal) []Signal {
@@ -241,3 +271,7 @@ func (o *Output)String() string {
func (o *Output)StateSnapshot() string {
return o.String()
}
func (o *Output)MermaidFlow() string {
return ""
}