#!/usr/bin/perl -w

use v5.16;
use strict;

my $in = 'cqjxxyzz';

NUMBER:
while (1) {
	my @l = split //, $in;
	my $n = $#l;
	while ($l[$n] eq 'z') {
		$l[$n] = 'a';
		$n--;
	}
	if ($l[$n] =~ /[hkn]/) {
		$l[$n] = chr(2+ord($l[$n]));
		while (++$n <= $#l) {
			$l[$n] = 'a';
		}
	} else {
		$l[$n] = chr(1+ord($l[$n]));
	};
	$in = join('', @l);
	say "got $in";

	next NUMBER if $in !~ /(.)\1.*(.)\2/;

	my $prev = $l[0];
	my $count = 1;
	for (1 .. $#l) {
		say "prev=$prev now=$l[$_] count $count";
		if ($prev eq chr(ord($l[$_])-1)) {
			last if ++$count >= 3;
		} else {
			$count = 1;
		}
		$prev = $l[$_];
	}
	next NUMBER if $count < 3;
	last;
}

