Exactly three adjacent 3 in lists: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Ring}}: needs improvement) |
|||
Line 151: | Line 151: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
{{improve|Ring|Works but is severely limited. What if you passed in the list [4,1,2,1,7,3,3,3]? (index bounds fault) or [9,2,4,1,2,1,7,3,3,3]? (incorrectly fails)}} |
|||
<lang ring> |
<lang ring> |
||
see "working..." + nl |
see "working..." + nl |
||
Line 165: | Line 165: | ||
good = 0 |
good = 0 |
||
cnt = 0 |
cnt = 0 |
||
len = len(list[n]) |
|||
for p = 1 to len |
|||
if list[n][p] = 3 |
if list[n][p] = 3 |
||
good++ |
good++ |
||
Line 171: | Line 172: | ||
next |
next |
||
if good = 3 |
if good = 3 |
||
for m = 1 to |
for m = 1 to len-2 |
||
if list[n][m] = 3 and list[n][m+1] = 3 and list[n][m+2] = 3 |
if list[n][m] = 3 and list[n][m+1] = 3 and list[n][m+2] = 3 |
||
cnt++ |
cnt++ |