User:Piphi/Asymptote/piphi

[asy]label(scale(2)*"The \texttt{piphi} module");[/asy]

My own unofficial Asymptote module with some useful functions:

Documentation

$\texttt{string [] array (string s);}$

This function is actually part of newer versions of Asymptote, but is not supported in 2.32 so I decided to make it. What it does is it takes a string and splits it into individual characters.

$\texttt{int length (int i);}$

Returns the number of digits in the given integer.

$\texttt{int int (string s);}$

Converts strings into integers.

Source Code

 1 /**
 2 * The piphi module
 3 * 
 4 * Made by piphi
 5 */
 6 
 7 string [] array (string s) {
 8     string[]strarray;
 9     for (int i=0;i<length(s);++i) {
10         strarray[i]=substr(s,i,1);
11     }
12     return strarray;
13 }
14 
15 int length (int i) {
16     int j=0;
17     bool brk=false;
18     do {
19         ++j;
20         if (i/(10**j) < 1) {
21             brk=true;
22         }
23     } while (!brk);
24     return j;
25 }
26 
27 int int (string s) {
28     string[]a=array(s);
29     int b;
30     for (int i=0;i<a.length;++i)
31         b+=(ascii(a[i])-48)*10**(a.length-i-1);
32     return b;
33 }
Invalid username
Login to AoPS