Author Topic: String to Number... ONE Number.  (Read 9063 times)

0 Members and 1 Guest are viewing this topic.

Offline bfr

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 819
  • Rating: +4/-0
    • View Profile
    • bfr's website
Re: String to Number... ONE Number.
« Reply #15 on: November 07, 2009, 02:23:41 pm »
You could do something like this:

Before you encode/decode:
Code: [Select]
"ABCDEFGHIJKLMNOPQRSTUVWXYZ ->Str2

To encode (input string in Str1, ouput number in Ans):
Code: [Select]
0
For(A,1,length(Str1
Ans+28^AinString(Str2,sub(Str1,A,1
End

To decode (input number in B, output string in Str3):
Code: [Select]
" ->Str3
For(A,2,12
int(28fPart(B/28^A
If Ans
Str3+sub(Str2,Ans,1->Str3
End

Then you could do sub(Str3,2,length(Str3)-1->Str3 to get rid of the space at the beginning.

In For(A,2,12 ,12 would be the maximum length of the string you'd expect.  I don't imagine these strings would be very long, or else accuracy would be lost fairly quickly (and then you'd get overflow errors too if they were over 69 characters or so).  You could also do a While loop or have a condition that exits the loop if int(28fPart(B/28^(A equals 0 too.  It could be rewritten many ways, such as even (I think this would work):

Code: [Select]
" ->Str3
1
For(A,2,99
Str3+sub(Str2,Ans,1->Str3
int(28fPart(B/28^A
If Ans
End

This would make the loop exit as soon as the number is finished being converted, while still using a For loop and not a While loop.  In this case you'd do sub(Str3,3,length(Str3)-2->Str3 to eliminate the stuff at the beginning.

Again, the main problem with this method would be possible loss of accuracy when calculating these really large numbers (the root of this problem would exist for pretty much any other string <-> number encoder/decoder because of the limit of how many digits the calculator stores - there are other more complicated methods such as using complex numbers to increase the limit, but not extremely significantly).  You could use base 27 instead of base 28 if you want by subtracting 1 from inString(Str2,sub(Str1,A,1 before multiplying it by 27^A, but I don't think it would matter much.
« Last Edit: November 07, 2009, 02:47:05 pm by bfr »

Offline jsj795

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1105
  • Rating: +84/-3
    • View Profile
Re: String to Number... ONE Number.
« Reply #16 on: November 07, 2009, 02:43:13 pm »
I got Data Type error in encoding... can't try out decoding if i can't encode :(


Spoiler For funny life mathematics:
1. ROMANCE MATHEMATICS
Smart man + smart woman = romance
Smart man + dumb woman = affair
Dumb man + smart woman = marriage
Dumb man + dumb woman = pregnancy
2. OFFICE ARITHMETIC
Smart boss + smart employee = profit
Smart boss + dumb employee = production
Dumb boss + smart employee = promotion
Dumb boss + dumb employee = overtime
3. SHOPPING MATH
A man will pay $2 for a $1 item he needs.
A woman will pay $1 for a $2 item that she doesn't need.
4. GENERAL EQUATIONS & STATISTICS
A woman worries about the future until she gets a husband.
A man never worries about the future until he gets a wife.
A successful man is one who makes more money than his wife can spend.
A successful woman is one who can find such a man.
5. HAPPINESS
To be happy with a man, you must understand him a lot and love him a little.
To be happy with a woman, you must love her a lot and not try to understand her at all.
6. LONGEVITY
Married men live longer than single men do, but married men are a lot more willing to die.
7. PROPENSITY TO CHANGE
A woman marries a man expecting he will change, but he doesn't.
A man marries a woman expecting that she won't change, and she does.
8. DISCUSSION TECHNIQUE
A woman has the last word in any argument.
Anything a man says after that is the beginning of a new argument.

Girls = Time * Money (Girls are a combination of time and money)
Time = Money (Time is money)
Girls = Money squared (So, girls are money squared)
Money = sqrt(Evil) (Money is also the root of all evil)
Girls = sqrt(Evil) squared (So, girls are the root of all evil squared)
Girls = Evil (Thus, girls are evil)
*Girls=Evil credit goes to Compynerd255*

Offline bfr

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 819
  • Rating: +4/-0
    • View Profile
    • bfr's website
Re: String to Number... ONE Number.
« Reply #17 on: November 07, 2009, 02:46:44 pm »
Oh, sorry, I forgot to include the first line of my code.  The encoding one should be:

Code: [Select]
0
For(A,1,length(Str1
Ans+28^AinString(Str2,sub(Str1,A,1
End

I'm going to update my previous post too.

Offline jsj795

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1105
  • Rating: +84/-3
    • View Profile
Re: String to Number... ONE Number.
« Reply #18 on: November 07, 2009, 03:42:34 pm »
I am uploading my program.
I think it's bug-free, but if you find one, tell me~
Oh, and when the string length goes over 10, it loses its accuracy


Spoiler For funny life mathematics:
1. ROMANCE MATHEMATICS
Smart man + smart woman = romance
Smart man + dumb woman = affair
Dumb man + smart woman = marriage
Dumb man + dumb woman = pregnancy
2. OFFICE ARITHMETIC
Smart boss + smart employee = profit
Smart boss + dumb employee = production
Dumb boss + smart employee = promotion
Dumb boss + dumb employee = overtime
3. SHOPPING MATH
A man will pay $2 for a $1 item he needs.
A woman will pay $1 for a $2 item that she doesn't need.
4. GENERAL EQUATIONS & STATISTICS
A woman worries about the future until she gets a husband.
A man never worries about the future until he gets a wife.
A successful man is one who makes more money than his wife can spend.
A successful woman is one who can find such a man.
5. HAPPINESS
To be happy with a man, you must understand him a lot and love him a little.
To be happy with a woman, you must love her a lot and not try to understand her at all.
6. LONGEVITY
Married men live longer than single men do, but married men are a lot more willing to die.
7. PROPENSITY TO CHANGE
A woman marries a man expecting he will change, but he doesn't.
A man marries a woman expecting that she won't change, and she does.
8. DISCUSSION TECHNIQUE
A woman has the last word in any argument.
Anything a man says after that is the beginning of a new argument.

Girls = Time * Money (Girls are a combination of time and money)
Time = Money (Time is money)
Girls = Money squared (So, girls are money squared)
Money = sqrt(Evil) (Money is also the root of all evil)
Girls = sqrt(Evil) squared (So, girls are the root of all evil squared)
Girls = Evil (Thus, girls are evil)
*Girls=Evil credit goes to Compynerd255*

Offline Raylin

  • Godslayer
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1392
  • Rating: +83/-25
  • I am a certifiable squirrel ninja.
    • View Profile
    • Ray M. Perry
Re: String to Number... ONE Number.
« Reply #19 on: November 08, 2009, 09:52:56 pm »
Mine's is a bit larger.
But, it keeps its accuracy after 10 characters and it can be as large as memory allows.
And it supports lower-case letters.

Hopefully, bug-free.
Might be slow.

Credit to me if you use please.

You may use the alternate name Raylin if you need to.
Bug me about my book.

Sarah: TI-83 Plus Silver Edition [OS 1.19]
Cassie: TI-86 [OS 1.XX]
Elizabeth: TI-81 [OS 1.XX]
Jehuty: TI-83 Plus Silver Edition [OS 1.19]
Tesla: CASIO Prizm







Offline jsj795

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1105
  • Rating: +84/-3
    • View Profile
Re: String to Number... ONE Number.
« Reply #20 on: November 09, 2009, 10:02:31 am »
My decoding is slow too, especially if you have Z in the string.
I am not at home right now, so can't download, will do it later~
For TLM, I at first decided to not use name, but through my program, will include naming once more, now with encoding and decoding haha
Thanks to you Prophets!


Spoiler For funny life mathematics:
1. ROMANCE MATHEMATICS
Smart man + smart woman = romance
Smart man + dumb woman = affair
Dumb man + smart woman = marriage
Dumb man + dumb woman = pregnancy
2. OFFICE ARITHMETIC
Smart boss + smart employee = profit
Smart boss + dumb employee = production
Dumb boss + smart employee = promotion
Dumb boss + dumb employee = overtime
3. SHOPPING MATH
A man will pay $2 for a $1 item he needs.
A woman will pay $1 for a $2 item that she doesn't need.
4. GENERAL EQUATIONS & STATISTICS
A woman worries about the future until she gets a husband.
A man never worries about the future until he gets a wife.
A successful man is one who makes more money than his wife can spend.
A successful woman is one who can find such a man.
5. HAPPINESS
To be happy with a man, you must understand him a lot and love him a little.
To be happy with a woman, you must love her a lot and not try to understand her at all.
6. LONGEVITY
Married men live longer than single men do, but married men are a lot more willing to die.
7. PROPENSITY TO CHANGE
A woman marries a man expecting he will change, but he doesn't.
A man marries a woman expecting that she won't change, and she does.
8. DISCUSSION TECHNIQUE
A woman has the last word in any argument.
Anything a man says after that is the beginning of a new argument.

Girls = Time * Money (Girls are a combination of time and money)
Time = Money (Time is money)
Girls = Money squared (So, girls are money squared)
Money = sqrt(Evil) (Money is also the root of all evil)
Girls = sqrt(Evil) squared (So, girls are the root of all evil squared)
Girls = Evil (Thus, girls are evil)
*Girls=Evil credit goes to Compynerd255*

Offline Raylin

  • Godslayer
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1392
  • Rating: +83/-25
  • I am a certifiable squirrel ninja.
    • View Profile
    • Ray M. Perry
Re: String to Number... ONE Number.
« Reply #21 on: November 09, 2009, 03:24:30 pm »
Off-hand, what is TLM?
I've seen in in your signature multiple times.
Bug me about my book.

Sarah: TI-83 Plus Silver Edition [OS 1.19]
Cassie: TI-86 [OS 1.XX]
Elizabeth: TI-81 [OS 1.XX]
Jehuty: TI-83 Plus Silver Edition [OS 1.19]
Tesla: CASIO Prizm







Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: String to Number... ONE Number.
« Reply #22 on: November 09, 2009, 10:53:28 pm »
The Lost Map (some RPG he is working on ATM)

Offline jsj795

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1105
  • Rating: +84/-3
    • View Profile
Re: String to Number... ONE Number.
« Reply #23 on: November 10, 2009, 06:38:38 pm »
the Tale of the Lost Map to be exact, the RPG I'm making...


Spoiler For funny life mathematics:
1. ROMANCE MATHEMATICS
Smart man + smart woman = romance
Smart man + dumb woman = affair
Dumb man + smart woman = marriage
Dumb man + dumb woman = pregnancy
2. OFFICE ARITHMETIC
Smart boss + smart employee = profit
Smart boss + dumb employee = production
Dumb boss + smart employee = promotion
Dumb boss + dumb employee = overtime
3. SHOPPING MATH
A man will pay $2 for a $1 item he needs.
A woman will pay $1 for a $2 item that she doesn't need.
4. GENERAL EQUATIONS & STATISTICS
A woman worries about the future until she gets a husband.
A man never worries about the future until he gets a wife.
A successful man is one who makes more money than his wife can spend.
A successful woman is one who can find such a man.
5. HAPPINESS
To be happy with a man, you must understand him a lot and love him a little.
To be happy with a woman, you must love her a lot and not try to understand her at all.
6. LONGEVITY
Married men live longer than single men do, but married men are a lot more willing to die.
7. PROPENSITY TO CHANGE
A woman marries a man expecting he will change, but he doesn't.
A man marries a woman expecting that she won't change, and she does.
8. DISCUSSION TECHNIQUE
A woman has the last word in any argument.
Anything a man says after that is the beginning of a new argument.

Girls = Time * Money (Girls are a combination of time and money)
Time = Money (Time is money)
Girls = Money squared (So, girls are money squared)
Money = sqrt(Evil) (Money is also the root of all evil)
Girls = sqrt(Evil) squared (So, girls are the root of all evil squared)
Girls = Evil (Thus, girls are evil)
*Girls=Evil credit goes to Compynerd255*