I'm trying to use Twilio's <Say> verb to pronounce a sequence of digits clearly. I'm finding it is hard to generate a natural (half-second) pause between each digit. How do I do this correctly?
The <Pause> xml command only takes integer values for seconds, so it's too long to use.
From here: Link
When saying numbers, '12345' will be spoken as "twelve thousand three
hundred forty five." Whereas '1 2 3 4 5' will be spoken as "one two
three four five."
Punctuation such as commas and periods will be interpreted as natural
pauses by the speech engine.
If you want to insert a long pause try using the <Pause> verb. <Pause> should be placed outside <Say> tags, not nested inside them.
For less then one second pause:
<Say language="en-US" voice="alice">
Your verification code is 1,,,,2,,,,3,,,,4,,,,5
</Say>
You can increase and decrease the number of commas according to you convenience.
This is tangentially related, but I figured people looking for something similar would end up on this question (like I did).
I wanted the Say verb to read a US phone number in a natural 3-3-4 cadence. Here is some C# that does just that. I'm sure you can figure out how to translate it to other languages:
private static string SayNaturalNumber(string digits)
{
var newNumber = "";
for (int i = 0; i < digits.Length; i++)
{
if (i == 0)
newNumber += digits[i];
else
newNumber += " " + digits[i];
if (i == 2) //after third digit
newNumber += ",,,,";
if (i == 5) //after sixth digit
newNumber += ",,,,";
}
return newNumber;
}
Related
I recently began to study swift as my first programming language and there's a very simple term that i can't find an answer for it.
take a look at this code:
var a = [Int]()
repeat {
let randomNumbers = Int.random(in: 0...10)
if a.contains(randomNumbers) == false {
a.append(randomNumbers)
}
print(randomNumbers)
} while (a.count < 10)
so this code is supposed to add 10 numbers (no duplicates) from 0...10 into the array until all unique integers are listed. what I don't understand is the role of "while" here.
doesn't the last line mean the number of "generated numbers" must be less than 10? then why every time I run the code I get more than 10 numbers (say 30-40) in the console?
Also according to the code, this code must not generate dupes. then why do I get some numbers printed 2,3 times in the console?
you check if randomNumbers already added to array a, if yes, the loop will be executed again, until a.count < 10.
if you move the print statement inside the if statement, it will be printed exactly 10 times.
I have a number with fractional parts, but Google sheets ROUND function works only for first number specified in places parameter:
1.48852 => ROUND(1.48852) => 1
1.48852 => ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(1.48852,5),4),3),2),1),0) => 2
Is any function in Google sheets that would work as shown in the second case?
Basically, I want something like ROUND but work recursively.
To answer your question directly, no, I don't believe that there is any function that enables recursive rounding (or recursive anything for that matter).
However, with the same degree of curiosity that you showed in asking this question, I've looked at how I might achieve a recursive result through scripting. This is the result.
function reround(input) {
var num1 = 5;
do {
input = input.toFixed(num1);
input=+input;
num1--;
}while (num1 >-1); // continue running the loop while is greater than -1, i.e. until num1 = 0
return input;
}
This code gets entered as a script and then the function is available for use in the spreadsheet. It only takes one parameter (value) because the number of places is coded into the script. But no doubt, one could modify the code to accept the number of decimal places as a parameter also (I wasn't that curious;).
This is the sequence of values at each stage of the conventional and recursive rounding.
This is the log of values from the REROUND process.
Interesting to note the difference at three decimal places. It's not something that I've explored, so I don't have an explanation.
HI I know there have been may question about this here but I wasn't able to find a detailed enough answer, Wikipedia has two examples of ISIN and how is their checksum calculated.
The part of calculation that I'm struggling with is
Multiply the group containing the rightmost character
The way I understand this statement is:
Iterate through each character from right to left
once you stumble upon a character rather than digit record its position
if the position is an even number double all numeric values in even position
if the position is an odd number double all numeric values in odd position
My understanding has to be wrong because there are at least two problems:
Every ISIN starts with two character country code so position of rightmost character is always the first character
If you omit the first two characters then there is no explanation as to what to do with ISINs that are made up of all numbers (except for first two characters)
Note
isin.org contains even less information on verifying ISINs, they even use the same example as Wikipedia.
I agree with you; the definition on Wikipedia is not the clearest I have seen.
There's a piece of text just before the two examples that explains when one or the other algorithm should be used:
Since the NSIN element can be any alpha numeric sequence (9 characters), an odd number of letters will result in an even number of digits and an even number of letters will result in an odd number of digits. For an odd number of digits, the approach in the first example is used. For an even number of digits, the approach in the second example is used
The NSIN is identical to the ISIN, excluding the first two letters and the last digit; so if the ISIN is US0378331005 the NSIN is 037833100.
So, if you want to verify the checksum digit of US0378331005, you'll have to use the "first algorithm" because there are 9 digits in the NSIN. Conversely, if you want to check AU0000XVGZA3 you're going to use the "second algorithm" because the NSIN contains 4 digits.
As to the "first" and "second" algorithms, they're identical, with the only exception that in the former you'll multiply by 2 the group of odd digits, whereas in the latter you'll multiply by 2 the group of even digits.
Now, the good news is, you can get away without this overcomplicated algorithm.
You can, instead:
Take the ISIN except the last digit (which you'll want to verify)
Convert all letters to numbers, so to obtain a list of digits
Reverse the list of digits
All the digits in an odd position are doubled and their digits summed again if the result is >= 10
All the digits in an even position are taken as they are
Sum all the digits, take the modulo, subtract the result from 0 and take the absolute value
The only tricky step is #4. Let's clarify it with a mini-example.
Suppose the digits in an odd position are 4, 0, 7.
You'll double them and get: 8, 0, 14.
8 is not >= 10, so we take it as it is. Ditto for 0. 14 is >= 10, so we sum its digits again: 1+4=5.
The result of step #4 in this mini-example is, therefore: 8, 0, 5.
A minimal, working implementation in Python could look like this:
import string
isin = 'US4581401001'
def digit_sum(n):
return (n // 10) + (n % 10)
alphabet = {letter: value for (value, letter) in
enumerate(''.join(str(n) for n in range(10)) + string.ascii_uppercase)}
isin_to_digits = ''.join(str(d) for d in (alphabet[v] for v in isin[:-1]))
isin_sum = 0
for (i, c) in enumerate(reversed(isin_to_digits), 1):
if i % 2 == 1:
isin_sum += digit_sum(2*int(c))
else:
isin_sum += int(c)
checksum_digit = abs(- isin_sum % 10)
assert int(isin[-1]) == checksum_digit
Or, more crammed, just for functional fun:
checksum_digit = abs( - sum(digit_sum(2*int(c)) if i % 2 == 1 else int(c)
for (i, c) in enumerate(
reversed(''.join(str(d) for d in (alphabet[v] for v in isin[:-1]))), 1)) % 10)
I am creating a calculator app. For aesthetic reasons (numbers need to line up with an image), the result always needs to be five digits long, even if the first four digits are spaces or zeros. For example, the user enters 1+1, the result is 2, but my app should display it as "00002" or " 2".
How can I achieve this?
Well, you contradict yourself when you say the number should always be five digits long then say your app should display it as "00002" or "2". I'll assume you actually want the former? Here's a simple example assuming your number is int x.
int x = 2;
NSString *string = [NSString stringWithFormat:#"%05d", x];
I´ve read a lot of posts about this but all of them were to limit the number digits to show them(NSString) .In my case I have:
I compare two double values(wich are the "same"), each of them got from different mathematical operations. For example: (4.800000 and 4.800000)
double result1=4.800000, result2=4.800000
//compare the results:
if(result1==result2){
msg.text=#"well done!!";
}else if(result1>result2){
msg.text=#"continue your work";
}
"I´m working with money (4,80€)"
In the msg label i get "continue your work" message, not the "well done". I don´t even know if the comparison is done in a correct way.
I think that the best idea would be to limit 4.800000 to 4.80 in order to delete small values and get a exact comparison.(how could i do this?)
I DONT WANT to limit the number to two digits just to PRINT the solution, I want to WORK with that number.
You can do something like this:
double a = 2.55000, b = 2.55002;
if(fabs(a-b)<1e-3) {
// code here, a == b
} else {
// code here, a != b
}
use floor(<#double#>) to round down OR just subtract them and floor the result.
For a nice answer to this problem see:
https://stackoverflow.com/a/10335601/474896
Which could be summarized as a simple as:
if (fabs(x-y) < FLT_EPSILON) {/* ... */}
However since you you're working with money values you should check out NSDecimalNumber.
Or as Marcus Zarra puts it:
"If you are dealing with currency at all, then you should be using
NSDecimalNumber.".