Skip to content

Instantly share code, notes, and snippets.

@Enchan1207
Created December 17, 2021 01:15
Show Gist options
  • Save Enchan1207/60d553dccb5f5e9fd1309a2b4529c9d2 to your computer and use it in GitHub Desktop.
Save Enchan1207/60d553dccb5f5e9fd1309a2b4529c9d2 to your computer and use it in GitHub Desktop.
ナベアツをつくろう
#
# イテレータ上手く使えばナベアツを錬成できるのでは?
#
import sys
from typing import Optional, Union
class Nabeatsu:
def __init__(self, start: int, end: int) -> None:
self.current = start
self.end = end
def __iter__(self):
return self
def __next__(self) -> Union[int, str]:
current = self.current
if current + 1 > self.end:
raise StopIteration
self.current += 1
# 3の倍数と3のつく数値の時だけアホになります
if current > 0 and (current % 3 == 0 or str(current).find('3') >= 0):
current_least_digit = int(str(current)[-1])
current_shouts = [
"ゥゥ-!", "ィィ--ッ!!", "ィ-!", "ァァァ--ン!!", "ォォ-ン!!",
"ォ--!", "ゥゥ-!", "ァァ--!", "ィ-!", "ゥ-!"
]
return f"{current}{current_shouts[current_least_digit]}"
return current
args = sys.argv
def value_or_none(list, index):
try:
return list[index]
except IndexError:
return None
start = int(value_or_none(args, 1) or "0")
end = int(value_or_none(args, 2) or "100") + 1
nabeatsu = Nabeatsu(start, end)
for n in nabeatsu:
print(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment