6
1
Your goal is to map a piece of text to a sine curve of the form:
a sin ( mx - b )
Where a and m are non-zero rational numbers, b is a rational number, and the calculations are in radians.
It doesn't really matter where the origin of your graph is, as long as you fit all the letters in your output. Also, it must be ASCII art, no graphical output.
You can take the equation input in as a string OR you can have a separate input for each parameter: a, m, and b.
Also
Examples:
Input: "A-well-a", "3sin(x)" or (3,1,0)
Output:
-w a A e - l l
Explanation:
The index of the character is the x-value, and each line represents one y-value. So we take 3sin(x) of the appropriate indices and round them to the nearest integer to get our values:
'A' : 3sin(0) = 0 => (0,0) '-' : 3sin(1) = 2.5244 => (1,3) 'w' : 3sin(2) = 2.7279 => (2,3) etc. , to give you the rest of the word.
Input: "Everybody's", "3.5sin(x-2)" or (3.5,1,2)
Calculations:
3.5sin(x-2), x = 0,1,2,3,...,10 -3.1815,-2.9435,0,2.9435,3.1815,0.4935,-2.6495,-3.3565,-0.9765,2.2995,3.4615,
Output:
ry s ' e b y Ev od
Input: "heard", "4sin(2x)" or (4,2,0)
4sin(2x) [0-4] = 0,3.636,-3.028,-1.116,3.956,
Output:
e d h r a
Input: "about","-5sin(x+1)" or (-5,1,-1)
-5sin(x+1) [0-4] : -4.205,-4.545,-0.705,3.785,4.795,
Output:
t u o a b
Input: "the word", "-2.4sin(0.5x-1.2)" or (-2.4,0.5,1.2)
-2.4sin(0.5x-1.2) [0-7] : 2.2368,1.5456,0.4776,-0.7104,-1.7208,-2.3136,-2.3376,-1.7904
Output:
th e word
1What is the input format? Do we need to parse the expression as a string? – Zgarb – 2016-01-13T17:53:37.513
@Zgarb Actually, if your language supports abstract mathematical functions, you can use that datatype for the expression. – geokavel – 2016-01-13T18:02:18.320
so the input format is flexible? for instance, I could take the function input (in python) as "3*math.sin(x)"? – quintopia – 2016-01-13T18:19:06.103
@quintopia No, only if your language natively supports mathematical expressions as a dataype (like MATLAB or Mathematica). – geokavel – 2016-01-13T18:23:05.827
Otherwise, we have to take the input as a string exactly in the format you described? – quintopia – 2016-01-13T21:34:57.847
@quintopia Ok, it finally hit me what people may have been wondering about, so I have loosened the input rules. – geokavel – 2016-01-13T21:53:17.813
Can we accept the input just separated by spaces?
word a m b
EDIT: just realized this would break with words that have spaces in them, so just"word" a m b
? – JuanPotato – 2016-01-13T23:05:12.643@Juan yes that'll be alright – geokavel – 2016-01-13T23:09:07.887
Related. – Martin Ender – 2016-07-08T12:51:10.780