Computer Science Canada

Letters going up

Author:  Finaltank [ Mon Oct 10, 2005 11:24 am ]
Post subject:  Letters going up

How would you make letters increase?

Ex: A + 1 = B?

array of 1..26?

For an example: I want my output to be

code:

A
B
C
D
E
... (all the way to)
Z


or

code:

AA
AB
AC
AD
... (all the way to)
ZZ

Author:  TokenHerbz [ Mon Oct 10, 2005 1:31 pm ]
Post subject: 

Well ill show you the LONG way...

code:

var let: array 1 .. 26 of string

for i: 2 .. 26
    let(1) := "A"
    let(2) := "B"
    let(3) := "C"
    let(4) := "D"
    let(5) := "E"
    let(6) := "F"
    let(7) := "G"
    let(8) := "H"
    let(9) := "I"
    let(10) := "J"
    let(11) := "K"
    let(12) := "L"
    let(13) := "M"
    let(14) := "N"
    let(15) := "O"
    let(16) := "P"
    let(17) := "Q"
    let(18) := "R"
    let(19) := "S"
    let(20) := "T"
    let(21) := "U"
    let(22) := "V"
    let(23) := "W"
    let(24) := "X"
    let(25) := "Y"
    let(26) := "Z"
end for

for i: 1 .. 26
    put let(i), "   " ..
end for


Of course you DONT want to do this with AA-ZZ, so heres a hint..

Each letter has a number variable, and theres ALWAYS an easier way to creat somthing...

I dont want to give you the code for this, cause i think its for your homework, BUT, the abouve is just an example of how things would work, but imagine if there was a number... which reprsents the letter, without having to declare the letter??

Author:  Cervantes [ Mon Oct 10, 2005 1:46 pm ]
Post subject: 

Tokenherbz, why would you iterate from 2 to 26 in that initial for loop when you don't even use the index? You're just erasing values over and over again and rewriting them with the same values.

Finaltank, pretend you're counting in Base 26.
Also, look up ord and chr. There's a section in the String Manipulation tutorial.

Author:  Cervantes [ Mon Oct 10, 2005 1:57 pm ]
Post subject: 

Cervantes wrote:
Finaltank, pretend you're counting in Base 26.

In case you didn't know, you can use intstr to work in different bases:
code:

const base := 26

for i : 1 .. 26**2
    put intstr (i, 0, base)
end for

Now, you just need to use some string manipulation to convert that to all letters.

Author:  codemage [ Tue Oct 11, 2005 8:17 am ]
Post subject: 

Quote:
Also, look up ord and chr


Fastest/easiest way, IMHO.
These functions convert numbers to letters & vice-versa.

code:
put chr ((ord ("a") + 1))

this code will output the letter "b"

Note - the letter "Z" will be a special case if you do it this way.


: