DEV Community

loading...

Discussion on: Daily Challenge #12 - Next Larger Number

Collapse
jacoby profile image
Dave Jacoby

Perl 5

#!/usr/bin/env perl

use strict;
use warnings;
use utf8;
use feature qw{ postderef say signatures state switch };
no warnings
    qw{ experimental::postderef experimental::smartmatch experimental::signatures };

use Algorithm::Permute;
use JSON;

my $json = JSON->new->pretty->canonical;

my $base = 2019;
my @base = split m{},$base;
my $iter = Algorithm::Permute->new(\@base);
my @list;
while ( my @num = $iter->next ) {
    push @list, join '', @num;
}
for my $n ( sort @list ) {
    next if $n <= $base;
    say $n;
    exit;
}
Collapse
choroba profile image
E. Choroba

Why JSON?

Collapse
jacoby profile image
Dave Jacoby

Because debugging and forgetting to remove it when done.