Square Number Digit Density The square number digit density (SNDD) of a number - invented by myself - is the ratio of the count of square numbers found in consecutive digits to the length of the number.  For instance, 169 is a 3-digit number containing 4 square numbers - 1, 9, 16, 169 - and thus has a square number digit density of 4/3, or 1.33.  The 4-digit number 1444 has 6 squares - 1, 4, 4, 4, 144, 1444 - and thus a ratio of 6/4, or 1.5.  Notice in the previous example that squares are allowed to be repeated.  Also, 441 is not allowed, because it cannot be found consecutively inside the number 1444.

Your task is to write a program that searches a given range A - B (inclusive) for the number with the highest square number digit density.  Your program should abide by the following specifications:


Take input A, B in the range 1 to 1,000,000,000 (1 billion).  Example: sndd 50 1000
Return as a result the number with the largest SNDD.  In the case of a tie, return the smallest number.
0 does not count as a square in any form, 0, 00, 000, etc.  Neither do squares starting with 0, such as 049 or 0049.
Note that the entire number does not have to be a square number.


Examples:

sndd 14000 15000
Output: 14441

sndd 300 500
Output: 441


Bonus: What is the number with the largest SNDD between 1 and 1,000,000,000?  Can you prove whether this is the largest possible, or there might be a larger one in a higher range?

Current Scores:


Ruby: 142
Windows PowerShell: 153
Scala: 222
Python: 245


Now that an answer has been selected, here is my (ungolfed) reference implementation in JavaScript: http://jsfiddle.net/ywc25/2/
Answering the bonus: the best score for numbers &lt;1e9 is 5/3=1.666..., generated by 144411449 (and maybe others?).

But you can do better with larger numbers.  Generally if n has a score of x, then you can concatenate two copies of n and get the same score x.  If you're lucky and n has the same first and last digit, then you can drop one of those digits in the concatenation and improve your score slightly (one less than double the number of squares and one less than double the number of digits).

n=11449441 has a score of 1.625 and has the same first &amp; last digit.  Using that fact, we get the following sequence of scores:

1.625 for 11449441
1.666 for 114494411449441
1.682 for 1144944114494411449441
1.690 for 11449441144944114494411449441
1.694 for 114494411449441144944114494411449441


which gives an infinite sequence of numbers which are strictly (although decreasingly) better than previous numbers, and all but the first 2 better than the best score for numbers &lt; 1e9.

This sequence may not be the best overall, though.  It converges to a finite score (12/7=1.714) and there may be other numbers with better scores than the limit.

Edit: a better sequence, converges to 1.75

1.600 14441
1.667 144414441
1.692 1444144414441
1.706 14441444144414441
1.714 144414441444144414441