DEV Community

Discussion on: Daily Challenge #71 - See you next Happy Year

Collapse
 
choroba profile image
E. Choroba

Using a regex in Perl:

#!/usr/bin/perl
use warnings;
use strict;

sub next_happy_year {
    my ($year) = @_;
    1 while ++$year =~ /(.).*\1/;
    $year
}

use Test::More tests => 3;

is next_happy_year(7712) => 7801;
is next_happy_year(1001) => 1023;
is next_happy_year(2018) => 2019;