How to make the π and 16 be on the same line? - ti-basic

So, I'm making a program on my TI-84 Plus that finds the area of a circle. I want it to display the approximate answer and the exact answer, but I can't get the latter to work. The code is this (I realize that it isn't very efficient):
Prompt R
ClrHome
(πR²)→A
(R²)→B
round(B,2)→B
Disp "A="
Disp ""
Disp "APPROXIMATION:"
Disp A
Disp "EXACT:"
Disp "π",B
Disp "PRESS ENTER"
Pause
However, it displays like this (when the radius is 4):
A=
APPROXIMATION:
50.27
EXACT:
π
16
PRESS ENTER
I would like to know how to make the π and 16 (in this case) be on the same line, with π before 16, and have it work for all number of digits. I've tried to use the Output( command, but if B is over 2 digits, it goes to the next line. Thanks!

Perhaps use Output(X,Y,"π") and Output(X,Y-3,B)
This is how I would do this:
:Prompt R
:ClrHome
:(πR²)→A
:(R²)→B
:log(B)→C
:round(B,2)→B
:Output(1,1,"A")
:Output(3,1,"APPROXIMATION:")
:Output(3,16,A)
:Output(5,1,"EXACT:")
:Output(5,8,B)
:Output(5,11+C,"π")
:Output(7,1,"PRESS ENTER")
:Pause
Basically, once the calculations are made, in this prgm text, the program would use log(B)→C to find how many spaces to move the π to the right. After that, it would output A at the first line of text, the approximation at the third line of the Home Screen grid (for Output), and the exact approximation, in terms of π, at the fifth line of the Home Screen grid (for Output).
Hope this helps!

Personally, I tend to use Output( for displaying text, but there are another two ways you could do this.
You could use Text( (under the Draw menu) to write text to the graph screen. For this, you need to make sure that all graphs are off, axes are off, and grid is off (grid only applies for TI84 +C Silver Edition as far as I know).
You can use Disp to display a string containing the values you want. For this, you need to turn the value of B into a string. There are a few ways you can do this, one posted here.

Related

Give an example of algorithm that is output sensitive, but not input sensitive

Could this be an example ?
x = randomNumber()
If x < 100 add x to the list and go to step 1.
Print list
Wikipedia says: "An output-sensitive algorithm is an algorithm whose running time depends on the size of the output." So, that's pretty easy:
Choose a random number in some range, say 10-1000.
Output that many dots.
The more dots, the longer it takes for your program to run. To make it more dramatic, you can pause for a second between dots.
Your example works too, since the longer the program runs (when the numbers happen to be small), the larger the output will be.

How to decrease motion times in vim, specifically decreasing key depress reaction time?

I'm wondering how to navigate vim more quickly within paragraphs. It seems ( ) are not as efficient as just holding down E/W/B if it is a very small paragraph because of the tendency to overshoot your intended location, which I still do, thus I end up doing something like EEEEEEE/BBBB/EE/B to get to the intended spot. On a related note, how can you make it so that when you hold down a motion key in vim, the motion will begin being implemented faster?
Vim offers a lot of ways to make your cursor movement more efficient. A few of them include:
f<character>  Jump to the next occurrence of "<character>"
gj or gk Treat a wrapped line as multiple lines
<number>b or <number>w Move <number> words
0 Jump to column 0

Convert from fraction to decimal and vice versa, TI 83 basic

I have a code to calculate the slope of a line if two points are known; however, it only returns the slope in decimal format. I'd like the ability to choose to convert the decimal to a fraction. Here's what I've done so far:
:Disp " "
:Input "PAIR 1: ",T
:Input "PAIR 2: ",U
:((LU(2)-LT(2))/(LU(1)-LT(2)))->M
:Disp "Slope Is: ",M
:Input "F>>D? Y/N: ",Str0
:If Str0="Y"
:(M>F<>D)->O
:Disp O
When I run this, I get ERROR: SYNTAX on the conversion step (the actual slope calculation completes successfully.)
**Some of the code I've typed above is not exactly how it appears in the TI 84, but it's the best I can do with a QWERTY keyboard.
►Frac and ►F◄►D are display tokens, not conversion tokens
TI calculators can only store numbers one way: in their proprietary floating-point format. This means that numbers cannot be "converted" from fraction to decimal or vice versa, only displayed as fractions or decimals. Thus, storing to anything (e.g. 3►F◄►D→X) will throw a syntax error.
Display modes are changed using the Auto/Dec/Frac tokens in the MODE menu; ►Frac overrides the mode and displays as a fraction approximation, ►Dec displays as decimal, and ►F◄►D tells the calculator to display in the opposite display mode from its current setting.
Quoting from this page:
►Frac attempts to display the input in fraction form. It only works on the home screen outside a program, or with the Disp and Pause commands in a program.
The trouble is in the line
(M>F<>D)->O
Disp O
There's no reason to format it this way when it can simply be expressed as
Disp M>F<>D
which calculates properly.
One way to convert from decimal to a fraction is to use the Euclidean Algorithm. Here it is in ti-basic
:Ans→X:{1,abs(Ans
:Repeat E‾9>Ans(2
:abs(Ans(2){1,fPart(Ans(1)/Ans(2
:End
:round({X,1}/Ans(1),0
:Ans/gcd(Ans(1),Ans(2
Ans is the decimal you wish to convert
and E‾9 is the same as 10^(-9)

ZPL - Code 128 Understanding better how to use Subsets B and C

I'm getting involved with ZPL (a little bit) since a few days, so I'm sorry if the questions will look stupid.
I've got to build a bar code 128 and I finally realized: I got to make it as shorter as possible.
My main question is: is it possible to switch to subset C and then back to B for just 2 digits? I read the documentation and subset C will ready digits from 00 to 99, so in theory it should work, practically, will it be worth it?
Basically when I translate a bar code with Zebra designer, and print it to a file, it doesn't bother to switch to subset C for just a couple of digits.
This is the text I need to see in the bar code:
AB1C234D567890123456
By the documentation I read, I would build something like this:
FD>:AB1C>523>64D>5567890123456
Instead Zebra Designer does:
FD>:AB1C234D>5567890123456
So the other question is, will the bar code be the same length? Actually, will mine be shorter? [I don't have a printer with me at the moment]
Last question:
Let's say I don't want to spend much time scripting this up, will the following work ok, or will it make the bar code larger?
AB1C>523>64D>556>578>590>512>534>556
So I can just build a very simple script which checks two chars per time, if they're both numbers, then add >5 to the string.
Thank you :)
Ah, some nice loose terminology. Do you mean couple="exactly 2" or couple="a few"?
Changing from one subset to another takes one code element, so for exactly 2 digits, you'd need one element to change and one to represent the 2 digits in subset C. On the other hand, staying with your original subset would take 2 elements - so no, it's not worth the change.
Further, if you were to change to C for 2 digits and then back to your original, the change would actually be costly - C(12)B = 3 elements whereas 12 would only be 2.
If you repeat the exercise for 4 digits, then switching to C would generate C(12)(34) = 3 elements against 4 to stay with what you have; or C(12)(34)B = 4 elements if you switch and change back, or 4 elements if you stick - so no gain.
With 6 or more successive numerics, then you gain regardless of whether or not you switch back.
So overall,
2-digit terminal : No difference
2-digit other : code is longer
4-digit terminal : code is shorter
4-digit other : no difference
more than 4 digits : code is shorter.
And an ODD number of digits would need to be output in code A or B for the first digit and then the above table applies to the remainder.
This may not be the answer you're looking for, but specifying A (Automatic Mode) as the final parameter to the ^BC command will make the printer do this for you.
Example:
^XA
^FO100,100
^BY3
^BCN,100,N,N,A
^FD0123456789^FS
^XZ

decoding algorithm wanted

I receive encoded PDF files regularly. The encoding works like this:
the PDFs can be displayed correctly in Acrobat Reader
select all and copy the test via Acrobat Reader
and paste in a text editor
will show that the content are encoded
so, examples are:
13579 -> 3579;
hello -> jgnnq
it's basically an offset (maybe swap) of ASCII characters.
The question is how can I find the offset automatically when I have access to only a few samples. I cannot be sure whether the encoding offset is changed. All I know is some text will usually (if not always) show up, e.g. "Name:", "Summary:", "Total:", inside the PDF.
Thank you!
edit: thanks for the feedback. I'd try to break the question into smaller questions:
Part 1: How to detect identical part(s) inside string?
You need to brute-force it.
If those patterns are simple like +2 character code like in your examples (which is +2 char codes)
h i j
e f g
l m n
l m n
o p q
1 2 3
3 4 5
5 6 7
7 8 9
9 : ;
You could easily implement like this to check against knowns words
>>> text='jgnnq'
>>> knowns=['hello', '13579']
>>>
>>> for i in range(-5,+5): #check -5 to +5 char code range
... rot=''.join(chr(ord(j)+i) for j in text)
... for x in knowns:
... if x in rot:
... print rot
...
hello
Is the PDF going to contain symbolic (like math or proofs) or natural language text (English, French, etc)?
If the latter, you can use a frequency chart for letters (digraphs, trigraphs and a small dictionary of words if you want to go the distance). I think there are probably a few of these online. Here's a start. And more specifically letter frequencies.
Then, if you're sure it's a Caesar shift, you can grab the first 1000 characters or so and shift them forward by increasing amounts up to (I would guess) 127 or so. Take the resulting texts and calculate how close the frequencies match the average ones you found above. Here is information on that.
The linked letter frequencies page on Wikipedia shows only letters, so you may want to exclude them in your calculation, or better find a chart with them in it. You may also want to transform the entire resulting text into lowercase or uppercase (your preference) to treat letters the same regardless of case.
Edit - saw comment about character swapping
In this case, it's a substitution cipher, which can still be broken automatically, though this time you will probably want to have a digraph chart handy to do extra analysis. This is useful because there will quite possibly be a substitution that is "closer" to average language in terms of letter analysis than the correct one, but comparing digraph frequencies will let you rule it out.
Also, I suggested shifting the characters, then seeing how close the frequencies matched the average language frequencies. You can actually just calculate the frequencies in your ciphertext first, then try to line them up with the good values. I'm not sure which is better.
Hmmm, thats a tough one.
The only thing I can suggest is using a dictionary (along with some substitution cipher algorithms) may help in decoding some of the text.
But I cannot see a solution that will decode everything for you with the scenario you describe.
Why don't you paste some sample input and we can have ago at decoding it.
It's only possible then you have a lot of examples (examples count stops then: possible to get all the combinations or just an linear values dependency or idea of the scenario).
also this question : How would I reverse engineer a cryptographic algorithm? have some advices.
Do the encoded files open correctly in PDF readers other than Acrobat Reader? If so, you could just use a PDF library (e.g. PDF Clown) and use it to programmatically extract the text you need.

Resources