Talk:Modulinos: Difference between revisions
Content added Content deleted
(→Examples: Expanded needs for a modified task.) |
|||
Line 157: | Line 157: | ||
--[[User:Paddy3118|Paddy3118]] 07:45, 7 March 2011 (UTC) |
--[[User:Paddy3118|Paddy3118]] 07:45, 7 March 2011 (UTC) |
||
: Perfect example Paddy! Is Rosetta Code's main purpose to help coders in programming contests, or are you just framing the article with that mindset for easier reading? --[[User:Mcandre|Mcandre]] |
|||
:: Hi Mcandre, I was 'framing' with an eye to maybe rewriting the task goals in a manner that was easier for more people to understand. I'm glad that we are on the same wavelength so far on the goals, but as a task description, the above has holes: |
|||
::# It needs to specify a task for the program that is importing the library to do. Maybe: ''"Use the libraries hailstone function, in the standard manner, (or document how this use deviates from standard use of a library); to find the hailstone length returned most often for 1 <= n < 100,000"'' |
|||
::# It needs a solution in another language |
|||
::# It would be good, but probably not essential to get a solution in another non-scripting language too. |
|||
:: '''Here is more to flesh out an initial Python solution:''' |
|||
::<lang python>from collections import Counter |
|||
from executable_hailstone_library import hailstone |
|||
def hailstone_length_frequency(hrange): |
|||
return Counter(len(hailstone(n)) for n in hrange).most_common() |
|||
if __name__ == '__main__': |
|||
upto = 100000 |
|||
hlen, freq = hailstone_length_frequency(range(1, upto))[0] |
|||
print("The length of hailstone sequence that is most common for\n" |
|||
"hailstone(n) where 1<=n<%i, is %i. It occurs %i times." |
|||
% (upto, hlen, freq))</lang> |
|||
::'''Sample output''': |
|||
::<code>The length of hailstone sequence that is most common for</code> |
|||
::<code>hailstone(n) where 1<=n<100000, is 72. It occurs 1467 times</code> |
|||
:: '''So, who's for the change!''' --[[User:Paddy3118|Paddy3118]] 08:15, 13 March 2011 (UTC) |