:3
Everything is barely weeks. Everything is days. We have minutes to live.
- about me
- Github: @r1bb1t-h0l3
Everything is barely weeks. Everything is days. We have minutes to live.
Posted
In Python a set is considered to be an unordered collection of unique elements. I found out about this method when solving the From 1967 to 2013 Problem on DMOJ. I actually wrote a different solution initially, one that iterated through 4 digits, comparing them to each other, but then I noticed that the input can go up to the tens of thousands. Also my submission only passed half the test cases😩.
I knew I needed a better way so I started researching and found the set()
method. A set can be made from any iterable like a list, string or tuple and removes any duplicate values, which was perfect for this task.
I do feel like using set()
is almost cheating here, as I generally avoid using “Python magic” to solve challenges, but this solution just looks so elegant. Anyways, here it is:
# 56 From 1987 to 2013 ccc13s1
def digit_same(year) -> bool:
return len(set(year)) != len(year)
input_year = int(input())
year = str(input_year + 1)
while digit_same(year):
num_year = int(year)
num_year += 1
year = str(num_year)
print(year)
Author
ribbit
Categories
coding challenge