G'day thanos1983,

Here's a recursive function that, I believe, achieves what you're after.

#!/usr/bin/env perl -l use strict; use warnings; use constant BASE => ord('A') - 1; use constant MAX => ord('Z') - BASE; my @tests = ( 0 .. 3, 24 .. 28, 26**2+24 .. 26**2+28, 26**3+26**2+24 .. 26**3+26**2+28, ); print "IN: $_ OUT: ", translate($_) for @tests; sub translate { my ($in, $out) = @_; $out ||= []; return join '', @$out if $in == 0; my $mod = $in % MAX || MAX; unshift @$out, chr $mod + BASE; my $new_in = ($in - $mod) / MAX; translate($new_in, $out); }

Output:

IN: 0 OUT: IN: 1 OUT: A IN: 2 OUT: B IN: 3 OUT: C IN: 24 OUT: X IN: 25 OUT: Y IN: 26 OUT: Z IN: 27 OUT: AA IN: 28 OUT: AB IN: 700 OUT: ZX IN: 701 OUT: ZY IN: 702 OUT: ZZ IN: 703 OUT: AAA IN: 704 OUT: AAB IN: 18276 OUT: ZZX IN: 18277 OUT: ZZY IN: 18278 OUT: ZZZ IN: 18279 OUT: AAAA IN: 18280 OUT: AAAB
"I am not posting the code here as it is irrelevant and will only consume space, ..."

A cutdown version might have provided some context. Without that, I don't know exactly how you'd implement this solution. You'll probably want some validation of the input.

— Ken


In reply to Re: Split int into segments of max int 26 by kcott
in thread Split int into segments of max int 26 by thanos1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.