Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Patternal issues solution in Creative category for Number Length by smilicic
from random import shuffle
class NonDeterministicStringDigitIterator:
def __init__(self, to_iterate):
self.data = str(to_iterate.value)
def __iter__(self):
self.data_for_iteration = list(self.data)
return self
def __next__(self):
data = self.data_for_iteration
if not data:
raise StopIteration
shuffle(data)
first_letter, data = data[0], data[1:]
self.data_for_iteration = data
return first_letter
def __len__(self):
true_list = list(x==x for x in self)
return sum(true_list)
class NumberDigitsIteratorFacade:
def __init__(self, value, Strategy):
self.value = value
self.strategy = Strategy(self)
def __iter__(self):
return iter(self.strategy)
def __len__(self):
return len(self.strategy)
def number_length(a):
f = NumberDigitsIteratorFacade(a, NonDeterministicStringDigitIterator)
return len(f)
Nov. 16, 2020
Comments: