diff --git a/grow/definition.go b/grow/definition.go index 93f8d53..0861415 100644 --- a/grow/definition.go +++ b/grow/definition.go @@ -57,6 +57,15 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) { } if score > status.BestScore { + err = def.minifyProgram(prog) + if err != nil { + if statusChan != nil { + close(statusChan) + } + + return nil, err + } + status.BestScore = score status.BestProgram = prog.Copy() @@ -65,20 +74,6 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) { } if status.BestScore == status.TargetScore { - err = def.minifyProgram(prog) - if err != nil { - if statusChan != nil { - close(statusChan) - } - - return nil, err - } - status.BestProgram = prog.Copy() - - if statusChan != nil { - statusChan <- status - } - if statusChan != nil { close(statusChan) } diff --git a/grow/defs/pythag.yaml b/grow/defs/pythag.yaml index f23f748..2ba164b 100644 --- a/grow/defs/pythag.yaml +++ b/grow/defs/pythag.yaml @@ -19,3 +19,12 @@ samples: - in: [12,35] out: [37] + +- in: [9, 40] + out: [41] + +- in: [88, 105] + out: [137] + +- in: [161, 240] + out: [289] diff --git a/grow/mutate.go b/grow/mutate.go index da713e7..5cde07e 100644 --- a/grow/mutate.go +++ b/grow/mutate.go @@ -10,11 +10,7 @@ const instrucitonsPerFunctionStdDev = 10 const minifyPeriodMean = 10000 -func Mutate(def *Definition, prog *vm.Program) { - if rand.Intn(minifyPeriodMean) == 0 { - def.minifyProgram(prog) // ignore error - } - +func Mutate(_ *Definition, prog *vm.Program) { target := int(rand.NormFloat64()*instrucitonsPerFunctionStdDev + instructionsPerFunctionMean) if len(prog.Functions[0].Instructions) < target {