#!/usr/bin/perl
# your code goes here
sub makeIteratorClass {
my ($f) = @_;
sub gensym {
my @chars = ("A".."Z", "a".."z");
my $string;
$string .= $chars[rand @chars] for 1..8; };
my ($iv) = @_;
my $self = { iv => $iv };
my $sym = gensym();
*{ "$sym" . "::getNext" } = sub {
my ($self) = @_;
$self->{iv} = $f->($self->{iv});
};
}
}
my $plusOner = makeIteratorClass(sub { my ($x) = @_; $x + 1 });
my $o = $plusOner->(5);
IyEvdXNyL2Jpbi9wZXJsCiMgeW91ciBjb2RlIGdvZXMgaGVyZQoKc3ViIG1ha2VJdGVyYXRvckNsYXNzIHsKICAgICAgICBteSAoJGYpID0gQF87CgogICAgICAgIHN1YiBnZW5zeW0gewogICAgICAgICAgICAgICAgbXkgQGNoYXJzID0gKCJBIi4uIloiLCAiYSIuLiJ6Iik7CiAgICAgICAgICAgICAgICBteSAkc3RyaW5nOwogICAgICAgICAgICAgICAgJHN0cmluZyAuPSAkY2hhcnNbcmFuZCBAY2hhcnNdIGZvciAxLi44OwogICAgICAgICAgICAgICAgcmV0dXJuICRzdHJpbmc7CiAgICAgICAgfTsKCiAgICAgICAgcmV0dXJuIHN1YiB7CiAgICAgICAgICAgICAgICBteSAoJGl2KSA9IEBfOwoKICAgICAgICAgICAgICAgIG15ICRzZWxmID0geyBpdiA9PiAkaXYgfTsKICAgICAgICAgICAgICAgIG15ICRzeW0gPSBnZW5zeW0oKTsKICAgICAgICAgICAgICAgICp7ICIkc3ltIiAuICI6OmdldE5leHQiIH0gPSBzdWIgewogICAgICAgICAgICAgICAgICAgICAgICBteSAoJHNlbGYpID0gQF87CiAgICAgICAgICAgICAgICAgICAgICAgICRzZWxmLT57aXZ9ID0gJGYtPigkc2VsZi0+e2l2fSk7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAkc2VsZi0+e2l2fTsKICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgICBibGVzcyAkc2VsZiwgJHN5bTsKICAgICAgICAgICAgICAgIHJldHVybiAkc2VsZjsKICAgICAgICB9Cn0KCm15ICRwbHVzT25lciA9IG1ha2VJdGVyYXRvckNsYXNzKHN1YiB7IG15ICgkeCkgPSBAXzsgJHggKyAxIH0pOwpteSAkbyA9ICRwbHVzT25lci0+KDUpOwpwcmludCAkby0+Z2V0TmV4dCgpOwpwcmludCAkby0+Z2V0TmV4dCgpOwpwcmludCAkby0+Z2V0TmV4dCgpOw==