#!/usr/local/bin/perl -w # A script for working out Aronson's sequence which is defined as # # "T is the first, fourth, eleventh, sixteenth, twenty-fourth ... letter of this sentence." # # The first few values are 1, 4, 11, 16, 24, 29, 33, 35, 39 # # c.f http://www.research.att.com/cgi-bin/access.cgi/as/njas/sequences/eisA.cgi?Anum=005224 # copyright (c) Simon Wistow , 2001 # released under the terms of the GPL available from # http://www.gnu.org/licenses/gpl.txt # usage : takes a number which is the number of terms to calculate the sequence to use strict; use Lingua::EN::Numbers::Ordinate; use Lingua::EN::Inflect qw (NUMWORDS ORD); my @pos; my $sentence = "T is the "; my $limit = $ARGV[0] || 16; while ($limit--) { my $tmp; ($tmp = $sentence) =~ s/[^a-z]//ig; my $digit = ( defined ($pos[$#pos]) ? index ($tmp, 't', $pos[$#pos]+1 ) : 0 ) + 1; $sentence .= NUMWORDS ( ORD ($digit) ).", "; push @pos, $digit; } $sentence =~ s/,\s+$/ letter in this sentence./; print "$sentence\n\n"; print join ", ", @pos; print "\n"; exit 0;