Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/General-FizzBuzz/Python/general-fizzbuzz-1.py
Normal file
11
Task/General-FizzBuzz/Python/general-fizzbuzz-1.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def genfizzbuzz(factorwords, numbers):
|
||||
# sort entries by factor
|
||||
factorwords.sort(key=lambda factor_and_word: factor_and_word[0])
|
||||
lines = []
|
||||
for num in numbers:
|
||||
words = ''.join(word for factor, word in factorwords if (num % factor) == 0)
|
||||
lines.append(words if words else str(num))
|
||||
return '\n'.join(lines)
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(genfizzbuzz([(5, 'Buzz'), (3, 'Fizz'), (7, 'Baxx')], range(1, 21)))
|
||||
3
Task/General-FizzBuzz/Python/general-fizzbuzz-2.py
Normal file
3
Task/General-FizzBuzz/Python/general-fizzbuzz-2.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
n = 20
|
||||
mappings = {3: "Fizz", 5: "Buzz", 7: "Baxx"}
|
||||
for i in range(1, n+1): print(''.join(word * (i % key == 0) for key, word in mappings.items()) or i)
|
||||
36
Task/General-FizzBuzz/Python/general-fizzbuzz-3.py
Normal file
36
Task/General-FizzBuzz/Python/general-fizzbuzz-3.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from collections import defaultdict
|
||||
|
||||
N = 100
|
||||
FACTOR_TO_WORD = {
|
||||
3: "Fizz",
|
||||
5: "Buzz",
|
||||
}
|
||||
|
||||
def fizzbuzz(n=N, factor_to_word=FACTOR_TO_WORD):
|
||||
|
||||
factors = defaultdict(list)
|
||||
|
||||
for factor in factor_to_word:
|
||||
factors[factor].append(factor)
|
||||
|
||||
for i in range(1, n+1):
|
||||
res = ''
|
||||
for factor in sorted(factors.pop(i, ())):
|
||||
factors[i+factor].append(factor)
|
||||
res += factor_to_word[factor]
|
||||
yield res or i
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
n = int(input('Enter number: '))
|
||||
|
||||
mods = {
|
||||
int(k): v
|
||||
for k, v in (
|
||||
input('Enter "<factor> <word>" (without quotes): ').split(maxsplit=1)
|
||||
for _ in range(3)
|
||||
)
|
||||
}
|
||||
|
||||
for line in fizzbuzz(n, mods):
|
||||
print(line)
|
||||
32
Task/General-FizzBuzz/Python/general-fizzbuzz-4.py
Normal file
32
Task/General-FizzBuzz/Python/general-fizzbuzz-4.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from collections import defaultdict
|
||||
|
||||
n = 100
|
||||
mods = [
|
||||
(3, 'Fizz'),
|
||||
(5, 'Buzz'),
|
||||
]
|
||||
|
||||
def fizzbuzz(n=n, mods=mods):
|
||||
res = defaultdict(str)
|
||||
|
||||
for num, name in mods:
|
||||
for i in range(num, n+1, num):
|
||||
res[i] += name
|
||||
|
||||
return '\n'.join(res[i] or str(i) for i in range(1, n+1))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
n = int(input())
|
||||
|
||||
mods = []
|
||||
while len(mods) != 3: # for reading until EOF change 3 to -1
|
||||
try:
|
||||
line = input()
|
||||
except EOFError:
|
||||
break
|
||||
idx = line.find(' ') # preserves whitespace
|
||||
num, name = int(line[:idx]), line[idx+1:] # after the first space
|
||||
mods.append((num, name)) # preserves order and duplicate moduli
|
||||
|
||||
print(fizzbuzz(n, mods))
|
||||
Loading…
Add table
Add a link
Reference in a new issue