SRL Archive - First Scripts

Name to Number


smithsps

2008-03-05 19:24:30

I made this more of a fun script… :spot:

Please report any problems and post your number!:)

program NametoNumber;
//Made by Smithsps

var
Name, LetterChar, TotalStr, NameLengthStr, Exit1, Alpha : string;
NameLength, Total, NameNum, NameNum1, Calc : integer;
A : array of string;
B : array of integer;

procedure Report;
begin
TotalStr := inttostr(Total);
NameLengthStr := inttostr(NameLength);
writeln('Your number is: ' + TotalStr);
writeln('');
writeln('Made by smithsps');
writeln('');
end;

procedure Calculation;
begin
LetterChar := copy(Name, NameNum, NameNum1);
Alpha := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890';
for Calc := 1 to NameLength do
if(pos(LetterChar, Alpha) > 0) then
Total := Total + B[pos(LetterChar, Alpha) - 1];
end;

procedure Entry;
begin
ClearDebug;
Name := readln('What is your name?');
Name := uppercase(name);
NameLength := Length(Name);
NameNum := 0
NameNum1 := 1
Total := 0;
end;

procedure DeclareArray;
begin
setarraylength(A, 37);
A := ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
//////////////////////////////////
setarraylength(B,37);
B :=[13, 14, 70, 55, 41, 98, 73, 59, 20, 5, 47, 59, 52, 76, 37, 2, 83,
33, 95, 56, 12, 74, 82, 87, 64, 69, 0, 48, 35, 57, 22, 67, 40, 96, 54, 15, 67];
end;


begin
DeclareArray;
repeat
Entry;
Calculation;
Report;
Exit1 := readln('Would you like to quit? Y/N');
until(Exit1 = 'y') or (Exit1 = 'Y');
end.

I also used a random number generator to help. :p

program RandomNumberGenerator;

const
B = 100; //Maxium random number.
D = 10; //How many random numbers you need.

var
A, C : integer;
E : string;

begin
C := 0;
ClearDebug;
repeat
wait(50); // Adds to the effect. :)
A := random(B) + 1;
E := inttostr(A);
writeln(E);
C := C + 1;
until(D = C);
end.

Runescapian321

2008-03-05 20:18:20

Your number is: 1008

(First + Last)

I was hoping it'd be 1337 :p

Pretty decent script :)

Harry

2008-03-05 20:23:24

Your number is: 413

Made by smithsps

Successfully executed

Pretty cool I guess :)

smithsps

2008-03-05 20:42:05

Does any one have any suggestions? I can always improve.(h)



Edit: Script Updated to include numbers.

mikevskater

2008-03-05 21:52:51

procedure Calculation;
begin
LetterChar := copy(Name, NameNum, NameNum1);
repeat
if (LetterChar = 'A') then
Total := Total + B[0];
if (LetterChar = 'B') then
Total := Total + B[1];
if (LetterChar = 'C') then
Total := Total + B[2];
if (LetterChar = 'D') then
Total := Total + B[3];
if (LetterChar = 'E') then
Total := Total + B[4];
if (LetterChar = 'F') then
Total := Total + B[5];
if (LetterChar = 'G') then
Total := Total + B[6];
if (LetterChar = 'H') then
Total := Total + B[7];
if (LetterChar = 'I') then
Total := Total + B[8];
if (LetterChar = 'J') then
Total := Total + B[9];
if (LetterChar = 'K') then
Total := Total + B[10];
if (LetterChar = 'L') then
Total := Total + B[11];
if (LetterChar = 'M') then
Total := Total + B[12];
if (LetterChar = 'N') then
Total := Total + B[13];
if (LetterChar = 'O') then
Total := Total + B[14];
if (LetterChar = 'P') then
Total := Total + B[15];
if (LetterChar = 'Q') then
Total := Total + B[16];
if (LetterChar = 'R') then
Total := Total + B[17];
if (LetterChar = 'S') then
Total := Total + B[18];
if (LetterChar = 'T') then
Total := Total + B[19];
if (LetterChar = 'U') then
Total := Total + B[20];
if (LetterChar = 'V') then
Total := Total + B[21];
if (LetterChar = 'W') then
Total := Total + B[22];
if (LetterChar = 'X') then
Total := Total + B[23];
if (LetterChar = 'Y') then
Total := Total + B[24];
if (LetterChar = 'Z') then
Total := Total + B[25];
if (LetterChar = ' ') then
Total := Total + B[26];
if (LetterChar = '1') then
Total := Total + B[27];
if (LetterChar = '2') then
Total := Total + B[28];
if (LetterChar = '3') tHen
Total := Total + B[29];
if (LetterChar = '4') then
Total := Total + B[30];
if (LetterChar = '5') then
Total := Total + B[31];
if (LetterChar = '6') then
Total := Total + B[32];
if (LetterChar = '7') then
Total := Total + B[33];
if (LetterChar = '8') then
Total := Total + B[34];
if (LetterChar = '9') then
Total := Total + B[35];
if (LetterChar = '10') then
Total := Total + B[36];
if (LetterChar = '0') then
Total := Total + B[37];
NameNum := NameNum + 1;
until (NameNum = NameLength);
end;
^this should be this:
procedure Calculation;
begin
LetterChar := copy(Name, NameNum, NameNum1);
repeat
case lowercase(LetterChar) of
'a': Total := Total + B[0];
'b': Total := Total + B[1];
'b': Total := Total + B[2];
'd': Total := Total + B[3];
'e': Total := Total + B[4];
'f': Total := Total + B[5];
'g': Total := Total + B[6];
'h': Total := Total + B[7];
'i': Total := Total + B[8];
'j': Total := Total + B[9];
'k': Total := Total + B[10];
'l': Total := Total + B[11];
'm': Total := Total + B[12];
'n': Total := Total + B[13];
'o': Total := Total + B[14];
'p': Total := Total + B[15];
'q': Total := Total + B[16];
'r': Total := Total + B[17];
's': Total := Total + B[18];
't': Total := Total + B[19];
'u': Total := Total + B[20];
'v': Total := Total + B[21];
'w': Total := Total + B[22];
'x': Total := Total + B[23];
'y': Total := Total + B[24];
'z': Total := Total + B[25];
' ': Total := Total + B[26];
'1': Total := Total + B[27];
'2': Total := Total + B[28];
'3': Total := Total + B[29];
'4': Total := Total + B[30];
'5': Total := Total + B[31];
'6': Total := Total + B[32];
'7': Total := Total + B[33];
'8': Total := Total + B[34];
'9': Total := Total + B[35];
'10': Total := Total + B[36];
'0': Total := Total + B[37];
end;
NameNum := NameNum + 1;
until (NameNum = NameLength);
end;
cases make things look alot more professional.
[PHP]Your number is: 156

Made by smithsps

Successfully executed[/PHP]
man i got a really low number :(

Ps. is this your first script?

FrÕzÑ_§ÕµL

2008-03-05 21:54:24

Yea I do, use case LetterChar of lol, instead of all those if thens!

Edit : damn it he beat me!

mikevskater

2008-03-05 21:56:55

From: FrÕzÑ_§ÕµL
Yea I do, use case LetterChar of lol, instead of all those if thens!

Edit : damn it he beat me!

=P sorry m8 (Whats yo numb?)

smithsps

2008-03-05 22:15:38

@mikevskater
Thx I will update my script, and this is not my first script. My first script here was:
prime checker. It should be a few rows down.

@FrÕzÑ_§ÕµL
What were you planing on doing? ;)


Edit: Updated thx to mikevskater

bullzeye95

2008-03-05 22:21:26

program NametoNumber;
//Made by Smithsps

var
Name, LetterChar, TotalStr, NameLengthStr, exit1 : string;
NameLength, Total, NameNum, NameNum1 : integer;
A : array of string;
B : array of integer;

procedure Report;
begin
TotalStr := inttostr(Total);
NameLengthStr := inttostr(NameLength);
writeln('Your number is: ' + TotalStr);
writeln('');
writeln('Made by smithsps');
writeln('');
end;

procedure Calculation;
var
I: Integer;
S: String;
begin
S:= 'abcdefghijklmnopqrstuvqxyz 1234567890';
LetterChar := copy(Name, NameNum, NameNum1);
for I:= 1 to NameLength do
if(pos(Lowercase(LetterChar), S) > 0)then
Total:= Total + B[pos(Lowercase(LetterChar), S) - 1];
end;

procedure Entry;
begin
ClearDebug;
Name := readln('What is your name?');
Name := trim(name);
Name := uppercase(name);
NameLength := Length(Name);
NameNum := 0
NameNum1 := 1
Total := 0;
end;

procedure DeclareArray;
begin
A:= ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
B:= [13, 14, 70, 55, 41, 98, 73, 59, 20, 5, 47, 59, 52, 76, 37, 2, 83, 33, 95, 56, 12,
74, 82, 87, 64, 69, 0, 48, 35, 57, 22, 67, 40, 96, 54, 15, 67];

end;


begin
DeclareArray;
repeat
Entry;
Calculation;
Report;
exit1 := readln('Would you like to quit? Y/N');
until(exit1 = 'y') or (exit1 = 'Y');
end.
Notice how I declared the arrays and made the calculation…

Good job though :)

smithsps

2008-03-05 22:28:40

Wow i don't really understand it…:redface:
can you explain?

bullzeye95

2008-03-05 22:34:51

Alright, I'll start with declaring the arrays. You can just declare them like
MyArray:= [1, 2, 3];
instead of
MyArray[0]:= 1;
MyArray[1]:= 2;
MyArray[2]:= 3;

Then to the calculation procedure… first I just turned your repeat..until loop into a for loop. I then, instead of the case statement, or as you had first, the if..then statements, I simply made a string. Just think of it as an array of characters. It would just do the same thing as what you had, but it would instead get the position of the "array"… I explain things terribly, I'm sorry… Hopefully somebody who can explain better will come.

smithsps

2008-03-06 13:27:38

I think i kinda get it! :D

Edit : Updated

Brain

2008-03-06 13:32:46

darn it!!!!
i only got 70!!!!
guess im a total noob at that game :p

n3ss3s

2008-03-06 13:47:58

You might want a small function to get the alphabet number of a letter.


{*******************************************************************************
Function GetAlphabet(C: Char): Integer;
By: n3ss3s
Description: Returns the alphabetic number of a character.
*******************************************************************************}

Function GetAlphabet(C: Char): Integer;
Begin
Result := iAbs(65 - GetKeyCode(C)) + 1;
End;

mikevskater

2008-03-06 14:55:10

From: n3ss3s
You might want a small function to get the alphabet number of a letter.


{*******************************************************************************
Function GetAlphabet(C: Char): Integer;
By: n3ss3s
Description: Returns the alphabetic number of a character.
*******************************************************************************}

Function GetAlphabet(C: Char): Integer;
Begin
Result := iAbs(65 - GetKeyCode(C)) + 1;
End;

You should explain that to him, caus he wont get that if he doesn't get arrays…. like what the function returns/how.

mastaraymond

2008-03-06 15:57:46

Your number is: 627

Yay.

Btw n3s33s, Ord is way more professional xD. Ord > GetKeyCode.

smithsps

2008-03-06 17:39:59

Mike… i do understand… ;) I'm not a total noob.