TI-BASIC (TI-82) making output position dependent on number of digits of a variable - ti-basic

So I made a point system for a game on the TI-82. The points are stored as the variable P. I first tried using the Disp command to display the variable and text at the right place, but that didn't work with mixed text and variables. So instead I switched to using the output command, but that always puts the variable and text at a fixed position, which means that as the variable gets more digits, the space between the variable and text shrinks. I tried using the log of the variable for the position, but that didn't work because most of the time it returned decimals. Here is my current code for displaying the points:
Output(2,1,P
Output(2,3,"POINTS
Does anyone know how to increase the spacing between the variable and the text depending on how many digits the variable has?

Log works if you round it down and add 1.
int(log(P)) + 1
will give you the number of digits. Why not just round up instead? Because log(10) = 1 but 10 is 2 digits.

This is pretty simple, just put the variable after the points, so instead of doing:
Output(2,1,P
Output(2,3,"POINTS
Do instead:
Output(2,1,"POINTS
Output(2,8,P

Related

Only allow whole numbers but display with '.' on the thousand for easy read

I want to apply data validation to my column so as to only accept whole numbers.
However I want these to be displayed with a dot so as to make it easier to read later on.
e.g. input = 14354 which is valid and then displayed 14.354
the data validation regular expression I am ussing is:
=regexmatch(to_text(A2);"^\d+\.*\d+$")
and the custom formatting is:
#,##
for most this working fine, large numbers are displayed with the '.' and things it shouldnt accept it is rejecting.
However, in the case of numbers which are entered with a decimal point as these are hidden, it is accepting it as valid.
It is also changing the format to auto atic and reading as date such entries like: 15.4
I should point out that I am using sheets in spanish and therefore the , is the marker for decimal places.
What am i missing here??
Select the cell range then go to Data > Data validation...
Add a custom formula rule:
=mod(A1;1)=0
Try this one:
=and(regexmatch(to_text(A2);"^\d+(\.\d{3})*$");mod(A2;1)=0)
Improved your formula to only accept a dot when it is followed by 3 numbers (this way, we invalidate the date e.g A2)
Combining the improved formula of yours and Aresvik's modulo answer, we need to check if the value does not have decimal. (this way, we invalidate the decimal e.g A6)
When both returns true, this shall confirm that the number inputted is a whole number with no decimal and not a date.
Output:
Invalid inputted values:
A2 - 15.4
A6 - 16412,212

Multiply text file in Unix by a constant

How can a text file be multiplied in by a constant using shell commands?
For e.g there is a text file consisting the following numbers
-255.9641842033
-255.9667588863
-256.9777650145
-258.9777662459
-259.9777661194
This needs to be multiplied with a constant 19.123456789123 and save in new text file. How can the above be accomplished?
Looking forward to a reply.
This might be close, using Perl:
perl -pe 's/([+-]?[0-9.]+)/$1*19.123456789123/ge' YourFile
Sample Output
-4894.92001617493
-4894.96925301402
-4914.3031850202
-4952.55012214707
-4971.67357651707
That kind of says... "capture anything that starts with an optional plus or minus and has a bunch digits and decimal points and call it capture group 1. Replace that with whatever it was multiplied by your magic number. The e at the end, says to evaluate the right side as an expression rather than take it as a literal. The g at the end says to do it each and every time it occurs on each line, rather than just the first time."

Creating a percent counter in terminal in Ruby

I want to create a fake percent counter within terminal in Ruby somewhat like this:
percent = 0
(1..100).each{|x| sleep(0.05); print "#{percent+=1}%"}
How do I make it so that instead of printing percent over and over again it just increasing the value of percent by 1 but stays "in place".
Please note that this is for aesthetic purposes only.
Thanks
You just need to add the carriage return character (e.g \r) to the end of the string, this has the effect of clearing the line before you write to it again.
percent = 0
(1..100).each{|x| sleep(0.05); print "#{percent+=1}%\r"}
What it actually does is a bit more complex and there's a good explanation here.

How to implement Siri/Cortana like functionality in commandline?

I would like to implement a small subset of siri/cortana like features in command line.
For e.g.
$ What is the sum of 100 and 1000
> Response: 1100
$ What is the product of 10 and 12
> Response: 120
The questions are predefined regular expressions. It needs to call the matching function in ruby.
Pattern: What is the sum of (\d)+ and (\d)+
Ruby method to call: sum(a,b)
Any pointers/suggestion is appreciated.
That sounds exactly like cucumber, maybe take a look and see if you can just use their classes to hack something together :) ?
You could do something like the following:
question = gets.chomp
/\A.*(sum |product |quotient |difference )\D+([0-9]+)\D+([0-9]+).*\z/.match question
send($1, $2.to_i, $3.to_i)
Quick explanation for anyone that may be new to matching in Ruby:
This gets a line of input from the command line and scans it for a function name (i.e. sum, product, etc) followed by a space and potentially some non-digit characters. Then, it looks for a first number (similarly followed by a space and 0 or more non-digit characters) and a second number followed by nothing or anything. The parentheses determine what gets assigned to the variables preceded by a $, i.e. the substring that matches the contents of the first set of parentheses gets assigned to $1.
Next, it calls the method whose name is the value of $1 with the arguments (casted to integers) found in $2 and $3.
Obviously, this isn't generalized at all--you're putting the method names in the regex, and it's taking a fixed number of arguments--but it'll hopefully be useful for getting you on the right track.

Ruby (on Rails) Regex: removing thousands comma from numbers

This seems like a simple one, but I am missing something.
I have a number of inputs coming in from a variety of sources and in different formats.
Number inputs
123
123.45
123,45 (note the comma used here to denote decimals)
1,234
1,234.56
12,345.67
12,345,67 (note the comma used here to denote decimals)
Additional info on the inputs
Numbers will always be less than 1 million
EDIT: These are prices, so will either be whole integers or go to the hundredths place
I am trying to write a regex and use gsub to strip out the thousands comma. How do I do this?
I wrote a regex: myregex = /\d+(,)\d{3}/
When I test it in Rubular, it shows that it captures the comma only in the test cases that I want.
But when I run gsub, I get an empty string: inputstr.gsub(myregex,"")
It looks like gsub is capturing everything, not just the comma in (). Where am I going wrong?
result = inputstr.gsub(/,(?=\d{3}\b)/, '')
removes commas only if exactly three digits follow.
(?=...) is a lookahead assertion: It needs to be possible to be matched at the current position, but it's not becoming part of the text that is actually matched (and subsequently replaced).
You are confusing "match" with "capture": to "capture" means to save something so you can refer to it later. You want to capture not the comma, but everything else, and then use the captured portions to build your substitution string.
Try
myregex = /(\d+),(\d{3})/
inputstr.gsub(myregex,'\1\2')
In your example, it is possible to tell from the number of digits after the last separator (either , or .) that it is a decimal point, since there are 2 lone digits. For most cases, if the last group of digits does not have 3 digits then you can assume that the separator in front is decimal point. Another sign is the multiple appearance of a separator in big numbers allows us to differentiate between decimal point and separators.
However, I can give a string 123,456 or 123.456 without any sort of context. It is impossible to tell whether they are "123 thousand 456" or "123 point 456".
You need to scan the document to look for clue whether , is used for thousand separator or decimal point, and vice versa for .. With the context provided, then you can safely apply the same method to remove the thousand separators.
You may also want to check out this article on Wikipedia on the less common ways to specify separators or decimal points. Knowing and deciding not to support is better than assuming things will work.

Resources