Don't have an account? Register now to chat, post, use our tools, and much more.
» Goto page Previous  1, 2, 3 ... 8, 9, 10, 11, 12, 13  Next
Here's a version that supports decimal points and gives a fixed-length output:

Code:
```:Ans→A :abs(Ans→B :int(log(Ans+not(Ans→C :"+ :If A<0 :"- :For(D,-1,12 :If C=D :Ans+". :Ans+sub("0123456789",1+int(10fPart(B10^(D-C))),1 :End```
Yay for the Weregoose! That looks great, is about the same size, and is simpler with more features.
After I meandered to TI|BD, I saw a complaint as to round( 's inability to look past the ninth digit. Now, with N as the argument, we have:

Code:
```:10^(N-1-int(log(X :Ans‾¹int(XAns+(1≤2fPart(XAns```

Edit: While this routine keeps N digits, round( seems to base its calculation on the location of the decimal point. I'll grant mine similar behavior when I'm feeling up to it.
SirCmpwn wrote:
Number to String Alternative
The LinReg method is nice and well optimized, but has the downside of destroying the graph screen. Here's a version that doesn't. For small numbers, it's also faster.
...

That's a nice routine. Pity that I can't use it for one of my programs because I'm dealing with 8 digit numbers.
Weregoose, fascinating, I wonder why round() has that limitation. If you want to bug me about it one day, I'd love to dive into the OS and try to figure it out.
In my document processor, fishbot suggested I implement an auto-wordwrap feature, so here's a fragment of code that I believe I'm going to use for it. Basic string pixel width, for the small text( character set:
Inputs: Str1 is the string you're trying to find the width of
Str2 is a list of all the characters you will be using
L1 is a list of the width of all the characters you will be using, required to be in the same order as Str2.

Outputs: width of str1 stored to Ans

Code:
`sum(seq(L2(inString(Str2,sub(Str1,B,1))),B,1,length(Str1`

Enjoy!
I think that that is most useful when you provide the list and string that you need for the widths, no? That's excellent, though, and I'd be happy to generate that if you don't have it handy.

Code:
`A-BiPart(A/B)`

This will give a modular value of A/B.
Hehe, not a problem. I hope that you'll continue adding contributions to this thread, though!
Binary-Reflected Gray Code
Inputs:
Ans = Binary list (e.g., {1,0,1,0,1,0} for 42 = 1010102)
Outputs:
Ans = Gray code equivalent

Code:
`:abs(augment({Ans(1)},ΔList(Ans`
Good thinking there, Weregoose! It's been a while since I've thought about gray coding.
Carrying over from this topic...

Bitwise Operations
Inputs:
C = Gaussian integer (
a+bi)
L1 = 2^{0,1,2,...,n} (specify number of bits)
Outputs:
Ans = Decimal integer resulting from the bitwise operation on (
a,b)

Code:
```OR :sum(L1abs(0≠abs(int(2fPart(.5C/L1 AND :sum(L1abs(1<abs(int(2fPart(.5C/L1 XOR :sum(L1abs(1=abs(int(2fPart(.5C/L1 ```

From what I gather, this deals with unsigned integers only.

Replace abs( with not( for NOR/NAND/XNOR.

Code:
``` :DelVar CDelVar B :For(A,1,length(Str1 :If B<91 and "^"≠sub(Str1,A,1 //(the “^” is to know when you want to wrap the text. But any other symbol is fine too) :Then :If " "≠sub(Str1,A,1 :Text(C,B,sub(Str1,A,1 :B+5→B //(5 or 6 is fine, 5 is kinda squishy) :If A<length(Str1)-1 :Ans-2(" "≠sub(Str1,A,1→B :Else :DelVar B :C+7→C //(6 or 7, if you have lots of text 6 is better but 7 is easier to read) :End :B+4(B>89→B :A-(B>89→A :End ```

This works for me!
0rac343, could you give us some more information about what that routine is for and what inputs and outputs it has? I don't think it's relevant to the post directly above it, so it could use some clarification.
Recommended window settings:

Code:
```:FnOff :ClrDraw :GridOff :AxesOff :PlotsOff :ZStandard :ZInteger :4→XFact :4→YFact :Zoom In```

Die Pip Plotter
Inputs:
X = Integer from one through six
Outputs:
Drawing of corresponding die

Code:
```:Input X :ClrDraw :Line(2,2,2,-2 :Line(2,-2,-2,-2 :Line(-2,-2,-2,2 :Line(-2,2,2,2 :If fPart(.5X :Pt-On(0,0,3 :For(X,2,X :int(.5X-3(X>3 :Pt-On(1,Ans,3 :Pt-On(-1,-Ans,3 :End```

Five-Die Plotter
Inputs:
Ans = Five-element list of integers from one through six
Outputs:
Drawing of corresponding dice, displayed side-by-side

Code:
```:Input L1 :ClrDraw :For(I,-2,2 :4.7I→J :Ans-2 :Line(Ans+4,2,Ans+4,-2 :Line(Ans+4,-2,Ans,-2 :Line(Ans,-2,Ans,2 :Line(Ans,2,Ans+4,2 :If fPart(.5L1(I+3 :Pt-On(J,0,3 :For(X,2,L1(I+3 :int(.5X-3(X>3 :Pt-On(J+1,Ans,3 :Pt-On(J-1,-Ans,3 :End :End```
As always, Weregoose, you absolutely blow me away. Nice work.
Linear Equation/Inequality Solver
Inputs:
Str1 = First-order, univariate statement involving X and one relational operator
Outputs:
Reduced statement with X isolated to the LHS

Code:
```:">=≥<≠≤→Str2 :max(seq(inString(Str1,sub(Ans,X,1)),X,1,6 :expr("solve(("+sub(Str1,1,Ans-1)+")-("+sub(Str1,Ans+1,length(Str1)-Ans)+"),X,0 :Disp "X"+sub(Str2,sum(seq(expr(Str1),X,Ans-1,Ans+1){4,2,1}),1 :Ans►Frac```

Example: (-X-3)/9≥-5 returns X≤42 – see that the relation will switch sides if necessary.
Sierpinski Triangle
Inputs: None
Outputs: IFS-generated Sierpinski sieve fractal

Code:
```:0 :Repeat 0 :.5(Ans+e^(.5iπint(3rand :Pt-On(real(Ans),imag(Ans :End```

Other functions to try:

Code:
```:-.5(Ans+e^(.5iπint(3rand //Xmin=-1, Xmax=1, Ymin=-2/3, Ymax=1/3 :.5(Ansi+e^(.5iπint(3rand //Xmin=-1, Xmax=3/4, Ymin=-1/2, Ymax=√(3)/2 :.5(1+Anse^(.5iπint(3rand //Xmin=0, Xmax=1, Ymin=-1/4, Ymax=1/2```
Oh, wow, you never cease to amaze me...
Congrats !

Edit : I'd recommend, for the first code, something like :
Xmin = -1, Xmax = 1.1, Ymin = -.2, Ymax = 1
No points can ever be drawn outside of -1≤x≤1 and 0≤y≤1 for the first function.

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 ... 8, 9, 10, 11, 12, 13  Next
» All times are GMT - 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