HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Invert the colors of the graph

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
invertcolorsthegraph

Problem

I've heard that Lbl and Goto use up memory that they don't give back. I've noticed clearing the RAM on my calculator frees up a lot of space and makes my programs run a lot faster. Any suggestions on how to minimize memory leaks here would be greatly appreciated. (This code does function correctly other than leaking memory).

:-1->B
:Lbl H
:B+1->B
:0->A
:If B=95
:Goto E
:Lbl V
:Pxl-Change(A,B)
:A+1->A
:If A=63
:Goto H
:Goto V
:Lbl E


I've represented the STO→ character, with -> Also, the graph is 94 pixels wide and 62 pixels tall.

Solution

I've heard that Lbl and Goto use up memory that they don't give back

If you replace the following ...

:If B=95
:Goto E
... etc. ...
:Goto V
:Lbl E


... with ...

... etc. ...
:If B<95
:Goto V


... then you have eliminated the final Lbl E as well as its Goto.

I don't think you can do better than that: the remaining two gotos are required: unless you unroll the loops.

Code Snippets

:If B=95
:Goto E
... etc. ...
:Goto V
:Lbl E
... etc. ...
:If B<95
:Goto V

Context

StackExchange Code Review Q#39308, answer score: 5

Revisions (0)

No revisions yet.