25
4
This challenge is a little tricky, but rather simple, given a string s
:
meta.codegolf.stackexchange.com
Use the position of the character in the string as an x
coordinate and the ascii value as a y
coordinate. For the above string, the resultant set of coordinates would be:
0, 109
1, 101
2, 116
3, 97
4, 46
5, 99
6, 111
7, 100
8, 101
9, 103
10,111
11,108
12,102
13,46
14,115
15,116
16,97
17,99
18,107
19,101
20,120
21,99
22,104
23,97
24,110
25,103
26,101
27,46
28,99
29,111
30,109
Next, you must calculate both the slope and the y-intercept of the set you've garnered using Linear Regression, here's the set above plotted:
Which results in a best fit line of (0-indexed):
y = 0.014516129032258x + 99.266129032258
Here's the 1-indexed best-fit line:
y = 0.014516129032258x + 99.251612903226
So your program would return:
f("meta.codegolf.stackexchange.com") = [0.014516129032258, 99.266129032258]
Or (Any other sensible format):
f("meta.codegolf.stackexchange.com") = "0.014516129032258x + 99.266129032258"
Or (Any other sensible format):
f("meta.codegolf.stackexchange.com") = "0.014516129032258\n99.266129032258"
Or (Any other sensible format):
f("meta.codegolf.stackexchange.com") = "0.014516129032258 99.266129032258"
Just explain why it is returning in that format if it isn't obvious.
Some clarifying rules:
- Strings are 0-indexed or 1 indexed both are acceptable.
- Output may be on new lines, as a tuple, as an array or any other format.
- Precision of the output is arbitrary but should be enough to verify validity (min 5).
This is code-golf lowest byte-count wins.
3Do you have any link / formula to calculate the slope and the y-intercept? – Rod – 2017-01-09T17:56:28.257
1Agreed. You should include the method for computing the line in the question. – mbomb007 – 2017-01-09T17:58:31.920
16Dear Unclear-voters: While I agree that it is nice to have the formula, it is by no means necessary. Linear regression is a well-defined thing in the mathematical world, and the OP may want to leave finding the equation up to the reader. – Nathan Merrill – 2017-01-09T18:02:57.643
6https://en.wikipedia.org/wiki/Simple_linear_regression – Magic Octopus Urn – 2017-01-09T18:11:01.420
1There are many ways to perform linear regression. Some are estimations/approximations while other methodologies strive to be exact calculations. So, how you go about it is up to you. But you should be able to explain the method you chose. – Magic Octopus Urn – 2017-01-09T18:15:26.567
2Is it okay to return the actual equation of the best-fit line, such as
0.014516129032258x + 99.266129032258
? – Greg Martin – 2017-01-09T18:18:51.0471@GregMartin yes. As long as the slope and y-intercept are displayed in a sensible manner I will accept it. – Magic Octopus Urn – 2017-01-09T18:39:28.283
2
This challenge's title has put this wonderful song in my head for the rest of the day
– Luis Mendo – 2017-01-09T21:09:16.9231I joined this community just to up-vote this challenge! – CraigR8806 – 2017-01-10T15:52:19.463
@CraigR8806 have a look around, this is by far not even close to the best challenge out there. – Magic Octopus Urn – 2017-01-10T19:15:13.530
@carusocomputing I have been lurking through here for awhile and there are definitely some novel challenges. I found this one to be really interesting though. – CraigR8806 – 2017-01-10T19:16:45.050
1Obligatory xkcd. (Though the example in this challenge does have something of a pattern, the outliers really skew the line of best fit!) – DLosc – 2017-01-11T07:28:00.323