» Goto page Previous  1, 2, 3, 4 ... 13, 14, 15  Next
If it was at the very top of the program, there wouldn't be a noticeable size difference at all, but yes, the loop would still marginally be the faster of the two methods.
OK, its been a while now, but here's a nice size optimization I came across the other day while optimizing a friends code.

Code:
```I was optimizing curious onlooker's newer version of AntiNibblz (before he releases it) and I found a great optimization for size and a slight speed improvement (by slight, the only difference is that there are fewer lines to read through, thus it is faster). The code is good for things that require something to be done every set number of loops, say 10, but it isn't in a For( loop (it still works in for loops). Code: :IS>(B,1+10int(B/10 :Pxl-On(RandInt(1,61),RandInt(1,92 It of course can be modified for other use, and B is the variable that is going through (the example is for every 10th```
Convert A to a string

Code:
``` :0->C :While iPart(A :C+1->C :A/10->A :End :"0123456789->Str0 :" ->Str9 :If A<0 :Then :Str9+"-->Str9 :-A->A :End :While fPart(A :If not(C :Str9+".->Str9 :10A->A :Str9+sub(Str0,iPart(A)+1,1->Str9 :A-iPart(A->A :C-1->C :End :If Str9=" :" 0->Str9 :sub(Str9,2,length(Str9)-1->Str9 ```

It's probably not as optimized as it could be, but I feel it's quite clever.
Convert A to a String [optimized]

Code:
``` :DelVar CWhile iPart(A :C+1->C :.1A->A :End :" ->Str9 :If A<0 :Then :Str9+"-->Str9 :-A->A :End :While fPart(A :If not(C :Str9+".->Str9 :10A->A :Str9+sub("0123456789",iPart(A)+1,1->Str9 :A-iPart(A->A :C-1->C :End :If Str9=" :" 0->Str9 :sub(Str9,2,length(Str9)-1->Str9 ```

Only a few optimizations made. No longer uses Str0.
Convert A to a String [optimized]

Code:
``` {A,A->L2 {0,1->L1 LinReg(a+bx) Y1 Equ>String(Y1,Str1 sub(Str1,1,length(Str1)-3->Str1 ```

--Code by Weregoose
Super Speler wrote:
Convert A to a String [optimized]

Code:
``` {A,A->L2 {0,1->L1 LinReg(a+bx) Y1 Equ>String(Y1,Str1 sub(Str1,1,length(Str1)-3->Str1 ```

--Code by Weregoose
Once I see that, it seems so obvious.
O_O And that's why I prefer to work in assembly. Much easier to know
all of the commands and what ya can do with them.
Chop off first element of list
Input: Ans
Output: Ans
Input and output variables can be changed to whatever.

Code:
`ΔList(cumSum(Ans`

Rotate a 3x3 matrix 90°

Code:
`rowSwap(Ans<superscript T thing>,1,3`

Who wants to make Tetris?
KermMartian wrote:
Super Speler wrote:
Convert A to a String [optimized]

Code:
``` {A,A->L2 {0,1->L1 LinReg(a+bx) Y1 Equ>String(Y1,Str1 sub(Str1,1,length(Str1)-3->Str1 ```

--Code by Weregoose
Once I see that, it seems so obvious.

oops... I was thinking {0,A} & {A,0}.. sorry
What happens because it works for me.
@rthprog: What are you talking about? This part:
Code:
```{A,A->L2 {0,1->L1```
is algebraically equivalent to 0AX+1A = A.
Wrongo Kerm linreg(a+bx) outputs the linear equation containing the points from [xlistname] and [ylistname]using the syntax [xlistname],[ylistname],[freqlist],[equation] it uses L1 and L2 as a default so all we need it the equation(which can even be omitted if we don't want to store our results). In the case of this routine it does this. It finds the line containing the points (0,A) (1,A) which is Y1=A+0X and we remove the "=0X with the substring.
TheStorm wrote:
Wrongo Kerm linreg(a+bx) outputs the linear equation containing the points from [xlistname] and [ylistname]using the syntax [xlistname],[ylistname],[freqlist],[equation] it uses L1 and L2 as a default so all we need it the equation(which can even be omitted if we don't want to store our results). In the case of this routine it does this. It finds the line containing the points (0,A) (1,A) which is Y1=A+0X and we remove the "=0X with the substring.
That's precisely what I said, except I didn't go into the mechanics of how it works. Suffice it to say that using the LinReg/EquToString trick, precisely A with no other characters can be put into a string.
OK the I misunderstood what you said then because It looks like you are saying that imputing {A,A and {2,3 would output 3A+2AX which is not the case.
TheStorm wrote:
OK the I misunderstood what you said then because It looks like you are saying that imputing {A,A and {2,3 would output 3A+2AX which is not the case.
Ah, I see where you're confused. No, that wouldn't happen at all; instead, you'd still get A.
I know that this was mentioned earlier (more like two years ago i guess)..
Mode of List1
Input data into List1 first, then run the program

Outputs mode number

Code:
``` 0->dim(LIST2 For(Z,1,dim(LIST1 sum(LIST1=LIST1(Z->LIST2(Z End max(LIST2->A For(Z,1,dim(LIST2 If A=LIST2(Z:Goto 0 End Lbl 0:LIST1(Z ```

It's a bit longer than the previous posted one, but if in speed, this one would be much faster (by 6 seconds). If anyone out there is willing to optimize this more please do. =()
Scrambles LIST1
Input data into LIST1 before running the program
Outputs LIST1

Code:
``` 0->A dim(LIST1->dim(LIST2:Ans->dim(LIST3 For(Z,1,dim(LIST1 Lbl 0 randInt(1,dim(LIST1->X X->LIST3(Z If X=A:Goto 0 If 1<sum(X=LIST3:Goto 0 LIST1(Z->LIST2(X X->A End LIST2->LIST1 Pause LIST1 ```

This may still need optimizing, which is fine... But right now, i just can't think of anything...
QuinnZhao wrote:
Scrambles LIST1
Input data into LIST1 before running the program
Outputs LIST1

Code:
``` 0->A dim(LIST1->dim(LIST2:Ans->dim(LIST3 For(Z,1,dim(LIST1 Lbl 0 randInt(1,dim(LIST1->X X->LIST3(Z If X=A:Goto 0 If 1<sum(X=LIST3:Goto 0 LIST1(Z->LIST2(X X->A End LIST2->LIST1 Pause LIST1 ```

This may still need optimizing, which is fine... But right now, i just can't think of anything...

==============================

Code:
``` rand(dim(L1→L2 SortA(L2,L1 ```

==============================
Haha, nice one, I was going to suggest something like that.

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» Goto page Previous  1, 2, 3, 4 ... 13, 14, 15  Next
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum