Here is my solution using PHP:
if (!function_exists("hasUniqueDigits")) { function hasUniqueDigits(int $number): bool { $digits = str_split($number); return $digits === array_unique($digits); } } if (!function_exists("nextHappyYear")) { function nextHappyYear(int $year): int { $nextYear = $year + 1; while(!hasUniqueDigits($nextYear)) { $nextYear++; } return $nextYear; } }
And here is my unit tests:
use PHPUnit\Framework\TestCase; class NextHappyYearTest extends TestCase { public function testShouldReturnNextHappyYear() { $this->assertEquals(nextHappyYear(7712), 7801); } public function testShouldReturnOtherNextHappyYear() { $this->assertEquals(nextHappyYear(1001), 1023); } public function testShouldReturnOtherOtherNextHappyYear() { $this->assertEquals(nextHappyYear(2018), 2019); } }
Hope you like it :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
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.
Here is my solution using PHP:
And here is my unit tests:
Hope you like it :)