Darth Plaguies
BAN USERBasic problem ( thanks for pointing the flaw out *Satsuma * :) )
One way of doing this is :-
def find_max_flipped(bit_string):
partitions = bit_string.split('0')
max_item = ''
num = len(partitions)
if num is 1:
return ''
if num is len(bit_string) + 1:
return '0'
for i in range(1, num):
if partitions[i-1] is '' and partitions[i] is '':
continue
if partitions[i-1] is '' and partitions[i] is not '':
if len(max_item) < partitions[i] + 1:
max_item = '0' + partitions[i]
if partitions[i-1] is not '' and partitions[i] is '':
if len(max_item) < partitions[i-1] + 1:
max_item = partitions[i-1] + '0'
else:
# They can be merged
item = partitions[i-1] + '0' + partitions[i]
if len(item) > max_item:
max_item = item
return max_item
3 Regex matches.
import re
import sys
'''
We note that the strings can be :
1+01+ ; then the max match wins anyways
1+0
0+1
'''
def find_max_len(regex, bit_string):
res = re.findall(regex, bit_string)
ret = ''
for r in res:
if len(r) > len(ret):
ret = r
return ret
def find_max_regex(bit_string):
result = find_max_len('1+01+', bit_string)
find10 = re.search('1+0', bit_string)
find01 = re.search('01+', bit_string)
if result != '':
return result
if find01 is not None:
return find01.group()
if find10 is not None:
return find10.group()
if '0' in bit_string:
return '0'
return ''
f = find_max_regex(sys.argv[1])
print(f)
Note that GP is : a,ax,ax^2,....
- Darth Plaguies August 27, 2014while AP is : a, a+x, a+2x
Then simply for AP :
x = a[2] - a[1] = a[1] - a[0] means
while for GP
x = a[2]/a[1] = a[1]/a[0]