Created
March 8, 2024 01:01
-
-
Save alpaylan/e15eb265642d032a42fde3416a29118d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prop1 = lambda n : n % 2 == 0 | |
prop2 = lambda n : n % 3 == 0 | |
prop3 = lambda n : n % 5 == 0 | |
inputs = list(range(1, 1000)) | |
print('Funnel 1') | |
print('inputs:', len(inputs)) | |
phase1 = list(filter(prop1, inputs)) | |
print('After first funnel(n % 2):', len(phase1)) | |
phase2 = list(filter(prop2, phase1)) | |
print('After second funnel(n % 3):', len(phase2)) | |
phase3 = list(filter(prop3, phase2)) | |
print('After third funnel(n % 5):', len(phase3)) | |
print('Utility Rate:', round(len(phase3) / len(inputs) * 100, 2), '%') | |
print('Funnel 2') | |
prop21 = lambda n : n % 2 == 0 \ | |
or (n % 3 == 0 and n > 600) \ | |
or (n % 5 == 0 and n > 600) | |
print('inputs:', len(inputs)) | |
phase21 = list(filter(prop21, inputs)) | |
print('After first funnel(n % 2):', len(phase21)) | |
phase22 = list(filter(prop2, phase21)) | |
print('After second funnel(n % 3):', len(phase22)) | |
phase23 = list(filter(prop3, phase22)) | |
print('After third funnel(n % 5):', len(phase23)) | |
print('Utility Rate:', round(len(phase23) / len(inputs) * 100, 2), '%') | |
print('Utility Gain:', round((len(phase23) / len(phase3) - 1) * 100, 2), '%') | |
# Funnel 1 | |
# inputs: 999 | |
# After first funnel(n % 2): 499 | |
# After second funnel(n % 3): 166 | |
# After third funnel(n % 5): 33 | |
# Utility Rate: 3.3 % | |
# Funnel 2 | |
# inputs: 999 | |
# After first funnel(n % 2): 593 | |
# After second funnel(n % 3): 233 | |
# After third funnel(n % 5): 46 | |
# Utility Rate: 4.6 % | |
# Utility Gain: 39.39 % |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment