19 yo student *and* a full-time developer.
Building with Rails currently, exploring new frontiers.
I enjoy functional programming, Linux, FOSS, refactoring and mentoring :)
defmoduleDay71do@doc"""
Finds the next happy year after `year`.
iex> Day71.next_happy_year(7712)
7801
iex> Day71.next_happy_year(1001)
1023
iex> Day71.next_happy_year(2018)
2019
"""@specnext_happy_year(pos_integer)::pos_integerdefnext_happy_year(year)do(year+1)|>Stream.iterate(&(&1+1))|>Enum.find(&happy?/1)end@doc"""
Checks if a year is a happy year.
A year is happy if all its digits are unique.
iex> Day71.happy?(2019)
true
iex> Day71.happy?(2021)
false
"""@spechappy?(pos_integer)::booleandefhappy?(year)dodigits=Integer.digits(year)Enum.uniq(digits)==digitsendend
And a test file (just for the sake of completeness):
defmoduleDay71TestdouseExUnit.CasedoctestDay71end
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Elixir (now with doctests!):
And a test file (just for the sake of completeness):