256
I'm pretty sure this hasn't really been done before, at least in TI-BASIC, but if something similar exists, please notify me.
Last year, I was absolutely amazed by the simplicity and ingenuity of Google Calculator, especially where you can type in any expression using any units (and an optional unit to convert to), and I decided that that was something someone needed to code for TI calculators. Thus I went on a coding rage, and actually got much of it done within a month, to the point where you could type in something like 7 M * IN INTO CM CM and it would display 1778. Unfortunately, I couldn't figure out division, parentheses, or exponents, so I set it aside and continued with other projects. One day, I really needed to clear some ARC space, so I deleted the group where I had saved it (I called it CALCALCA). I finally started regretting this decision, and will start coding it again, but I really need help with the issues I mentioned above.
This is what I've decided for the program so far:
1. It will use a blank input (Input "",Str1) to input a continuous expression.
2. The resultant string will searched through first for illegal characters.
3. The string is checkeda second time, this time for the characters " INTO " (which specifies that the following units say what unit the user wants)
4. First, "(" is added to the beginning, and ")" to the end, just for padding (i.e., "("+Str1+")"→Str1)
5. The string is then evaluated, one character at a time.
a. Whenever it hits a space, it tests to see whether * follows it.
i. If there is one, the space is deleted by using sub('s for the two sides of the string.
ii. If there is not, the space is replaced with )(, which assumes the space meant implied multiplication.
b. Whenever it hits a letter, a subloop gets the entire combination of letters, which is saved to another string for checking.
i. The second string is checked against a database of all the units to be supported (see note below).
ii. If there is a match, that entire section of the main string is replaced with the numerical value of the unit, surrounded by "(" and ")", and the unit's base units are added to alist (see second note below). matrix.
c. Whenever it hits a number, ".", "*", or "E", it it added directly.
d. Whenever it hits a "(", the matrix is widened by one, and base units added from then on are added to the new column.
e. Whenever it hits a ")", it stored the rightmost column into L1 and checks the following character.
i. If it is a "-1", L1 is inverted.
ii. If it is a "2", L1 is doubled.
iii. If it is a "^", another subloop is used to get the entire number following it, and L1 is multiplied accordingly.
iv. L1 is integrated into the next-rightmost column of the matrix.
6. When this is all done, the program will evaluate the string (with an exp() and (theoretically) appends the final unit.
Note:
The database consists of a huge (literally, huge, and might even be larger than the program itself) string containing each supported unit in the format:
Anyone willing to help me with this program? I currently have several programs in development simulataneously, and I can't finish this myself.
By the way, if anyone can't read the above code, I attached it as a .txt:
Last year, I was absolutely amazed by the simplicity and ingenuity of Google Calculator, especially where you can type in any expression using any units (and an optional unit to convert to), and I decided that that was something someone needed to code for TI calculators. Thus I went on a coding rage, and actually got much of it done within a month, to the point where you could type in something like 7 M * IN INTO CM CM and it would display 1778. Unfortunately, I couldn't figure out division, parentheses, or exponents, so I set it aside and continued with other projects. One day, I really needed to clear some ARC space, so I deleted the group where I had saved it (I called it CALCALCA). I finally started regretting this decision, and will start coding it again
This is what I've decided for the program so far:
1. It will use a blank input (Input "",Str1) to input a continuous expression.
3. The string is checked
4. First, "(" is added to the beginning, and ")" to the end, just for padding (i.e., "("+Str1+")"→Str1)
5. The string is then evaluated, one character at a time.
i. If there is one, the space is deleted by using sub('s for the two sides of the string.
ii. If there is not, the space is replaced with )(, which assumes the space meant implied multiplication.
b. Whenever it hits a letter, a subloop gets the entire combination of letters, which is saved to another string for checking.
i. The second string is checked against a database of all the units to be supported (see note below).
ii. If there is a match, that entire section of the main string is replaced with the numerical value of the unit, surrounded by "(" and ")", and the unit's base units are added to a
c. Whenever it hits a number, ".", "*", or "E", it it added directly.
d. Whenever it hits a "(", the matrix is widened by one, and base units added from then on are added to the new column.
e. Whenever it hits a ")", it stored the rightmost column into L1 and checks the following character.
i. If it is a "-1", L1 is inverted.
ii. If it is a "2", L1 is doubled.
iii. If it is a "^", another subloop is used to get the entire number following it, and L1 is multiplied accordingly.
iv. L1 is integrated into the next-rightmost column of the matrix.
6. When this is all done, the program will evaluate the string (with an exp() and (theoretically) appends the final unit.
Note:
The database consists of a huge (literally, huge, and might even be larger than the program itself) string containing each supported unit in the format:
Code: [Select]
" 2 Pa -1 01 00 -2 1.00000000 ..."
^ ^ | | ^ ^
| | +------------------+ | |
| | | | |
Length of Unit name. These four numbers are the How many of the Continue
unit name. base units for the unit, in unit fit into onto next
the order {length, mass, the base unit. unit.
current, time}. For example, Since pascals are
Pa=N/(m^2) the base for
=(kg*m/(s^2))/(m^2) pressure, this
=kg/(s^2)/m would be a one
so is mass (the positive (the zeroes are
one) divided by time squared because it needs
(the negative two) divided by to have exactly
length (the negative one). ten characters).
By the way, if anyone can't read the above code, I attached it as a .txt: