Post Reply 
Little explorations with HP calculators (no Prime)
12-28-2018, 01:38 AM (This post was last modified: 12-28-2018 01:55 AM by Albert Chan.)
Post: #325
RE: Little explorations with HP calculators (no Prime)
Perhaps variable "blue" is unnecessary, since False=0, True=1:

Code:
def match_count(thelist):
    return sum(sum(thelist[i:i+70]) == 50 for i in range(71))

To speed up above, cache sublist sum:

Code:
def match_count(thelist):
    head, tail = thelist[:70], thelist[70:]
    s = sum(head)
    n = s == 50
    for h, t in zip(head, tail):
        s = s - h + t
        if s==50: n = n + 1
    return n
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Little explorations with HP calculators (no Prime) - Albert Chan - 12-28-2018 01:38 AM



User(s) browsing this thread: 2 Guest(s)