[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

alphabet increment script

aidy

7/6/2007 12:39:00 PM

Hi,

I am trying to write a script where each line moves the character by 1
with 5 columns



AAAAA

AAAAB

AAAAC

....

AAAAZ

AAABA

AAABB

till we get to ZZZZ

This is what I have

j= 4
chars=['A','A','A','A','A']
chars[j].upto("Z") do |i|
chars[j] = i
print chars, "\n"
end
chars[j-1] = chars[j-1].succ!
chars[j]= 'A'
chars[j].upto("Z") do |i|
chars[j] = i
print chars, "\n"
end


But having some trouble

Aidy

4 Answers

BDB

7/6/2007 12:52:00 PM

0

On 2007-07-06 07:39:21 -0500, "aidy.lewis@googlemail.com"
<aidy.lewis@googlemail.com> said:

> Hi,
>
> I am trying to write a script where each line moves the character by 1
> with 5 columns
>
>
>
> AAAAA
>
> AAAAB
>
> AAAAC
>
> ...
>
> AAAAZ
>
> AAABA
>
> AAABB
>
> till we get to ZZZZ
>
> This is what I have
>
> j= 4
> chars=['A','A','A','A','A']
> chars[j].upto("Z") do |i|
> chars[j] = i
> print chars, "\n"
> end
> chars[j-1] = chars[j-1].succ!
> chars[j]= 'A'
> chars[j].upto("Z") do |i|
> chars[j] = i
> print chars, "\n"
> end
>
>
> But having some trouble
>
> Aidy

a='AAAAA'

while a != 'ZZZZZ' do
puts a
a = a.succ
end

# is this what you want?

--
H. Asari

aidy

7/6/2007 1:04:00 PM

0

On 6 Jul, 13:51, Banzai <noem...@yahoo.com> wrote:
Hi
> a='AAAAA'
>
> while a != 'ZZZZZ' do
> puts a
> a = a.succ
> end
>

Thanks for getting back. How would I include ZZZZ?

Aidy



aidy

7/6/2007 1:33:00 PM

0

On 6 Jul, 14:03, "aidy.le...@googlemail.com"
<aidy.le...@googlemail.com> wrote:
> On 6 Jul, 13:51, Banzai <noem...@yahoo.com> wrote:
> Hi
>
> > a='AAAAA'
>
> > while a != 'ZZZZZ' do
> > puts a
> > a = a.succ
> > end
>
> Thanks for getting back. How would I include ZZZZ?
>
> Aidy


Apologies

while a != 'AAAAAA' do

....

Aidy

Robert Klemme

7/7/2007 5:04:00 PM

0

On 06.07.2007 15:33, aidy.lewis@googlemail.com wrote:
> On 6 Jul, 14:03, "aidy.le...@googlemail.com"
> <aidy.le...@googlemail.com> wrote:
>> On 6 Jul, 13:51, Banzai <noem...@yahoo.com> wrote:
>> Hi
>>
>>> a='AAAAA'
>>> while a != 'ZZZZZ' do
>>> puts a
>>> a = a.succ
>>> end
>> Thanks for getting back. How would I include ZZZZ?
>>
>> Aidy
>
>
> Apologies
>
> while a != 'AAAAAA' do
>
> ...

You can as well do

'AAAAA' .. 'ZZZZZ'.each do |x|
puts x
end

or

for x in 'AAAAA' .. 'ZZZZZ'
puts x
end

Kind regards

robert