aboutsummaryrefslogtreecommitdiff
path: root/challenge-119/arne-sommer/perl/seq-without-single-perl
blob: 67e5e837f4bb706af585ea633956dc0f4cf5c488 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/env perl

use strict;
use warnings;
use feature 'say';

my $N = $ARGV[0] // "";


die "Please specify a positive integer" if $N !~ /^[1-9]\d*$/;

my $count   = 1;
my $current = 1;

while ($count < $N)
{
  my @digits  = split(//, reverse($current));
  my $new     = "";
  my $add     = 1;
    
  for my $digit (split(//, reverse($current)))
  {
    if ($add)
    {
      if ($digit <= 2)
      {
        $digit++;
        $add = 0;
      }
      else
      {
        $digit = 1;
      }
    }
      
    $new = $digit . $new;
  }

  $new = "1$new" if $add; 
  $current = $new;

  $count++ unless $current =~ /11/;
}

say $current;