PDA

View Full Version : Section ID Calculator (with correct math)


RagMasterRappy
11-18-2002, 11:34 AM
This is really easy to do, I can put the compiled Win32 executable somewhere if anyone wants it.

#include <stdio.h>

#define MAX_NAME_CHARS 12

#define MIN_VALID_CHAR 32
#define MAX_VALID_CHAR 126

int isValidName(char *name)
{
unsigned long i;

if (strlen(name) > MAX_NAME_CHARS)
return 0;

for (i=0; i<strlen(name); i++)
{
if (name[i] < MIN_VALID_CHAR || name[i] > MAX_VALID_CHAR)
return 0;
}

return 1;
}

unsigned long sumNameCharacters(char *name)
{
unsigned long result = 0;
unsigned long i;

for (i=0; i<strlen(name); i++)
result += name[i] % 10;

return result;
}

int main(int argc, char *argv[])
{
unsigned char *sectionIDNames[] = { "VIRDIA", "GREENILE", "SKYLY",
"BLUEFULL", "PURPLENIUM",
"PINKAL", "REDRIA", "ORAN",
"YELLOWBOZE", "WHITILL" };

if (argc < 2 || !isValidName(argv[1]))
{
fprintf(stderr, "PSO Section ID Calculatorn");
fprintf(stderr, "nUsage: sectid <your name>n");
fprintf(stderr, "Note that your name is limited to %d characters ", MAX_NAME_CHARS);
fprintf(stderr, "and can only includenalphanumeric ASCII characters!n");
return 1;
}

printf("%s's Section ID is %sn", argv[1],
sectionIDNames[sumNameCharacters(argv[1]) % 10]);

return 0;
}

eRUPT
11-18-2002, 11:51 AM
Go look in downloads I've had a section id caculator compiled, source, and linux shell script in the downloads section for a long time now.

RagMasterRappy
11-18-2002, 11:59 AM
On 2002-11-18 09:51, eRUPT wrote:
Go look in downloads I've had a section id caculator compiled, source, and linux shell script in the downloads section for a long time now.

Ok, I see it now, but it wasn't very clear that you had that sort of stuff here. Check out my tight formatting! http://www.pso-world.com/psoworld/images/phpbb/icons/smiles/icon_biggrin.gif
(Don't hit me, please.)

RagMasterRappy
11-18-2002, 12:18 PM
Here's the JavaScript version


<html>
<head>
<script>
var MAX_NAME_CHARS = 12;
var MIN_VALID_CHAR = 32;
var MAX_VALID_CHAR = 126;

function isValidName(name)
{
var i;

if (name.length > MAX_NAME_CHARS)
return 0;

for (i=0; i<name.length; i++)
{
if (name[i] < MIN_VALID_CHAR || name[i] > MAX_VALID_CHAR)
return 0;
}

return 1;
}

function sumNameCharacters(name)
{
var result = 0;
var i;

for (i=0; i<name.length; i++)
result += name.charCodeAt(i) % 10;

return result;
}

function main(name)
{
var sectionIDNames = new Array("VIRDIA", "GREENILE", "SKYLY",
"BLUEFULL", "PURPLENIUM",
"PINKAL", "REDRIA", "ORAN",
"YELLOWBOZE", "WHITILL");
var text = "";
var number;

if (!isValidName(name))
{
text += "Your name is limited to 12 characters and can only include alphanumeric ";
text += "ASCII characters!";
} else
text += name + "'s Section ID is " + sectionIDNames[sumNameCharacters(name) % 10];

return text;
}
</script>
</head>
<body>

Name: <input name="CharacterName" type="text" size="12"></input> <button onClick="alert(main(CharacterName.value));">Calculate</button>

</body>
</html>