![]() |
![]() |
#1 |
"Daniel Jackson"
May 2011
14285714285714285714
641 Posts |
![]()
Can someone please tell me where I can find a program that computes the reverse-and-add process for any input number? I can't find any that fit my needs:
1. It must be able to accept any seed number, even numbers >10911. 2. It must be able to calculate the process efficiently, even if the palindrome it outputs is greater than M57885161. Does anyone know where I can find such a program? I tried googling '"Reverse and add" software' and '"Reverse and add" program', but with no results. ![]() EDIT: If anyone wants to know, I need said program so I don't have to manually type in "2147483647+7463847412+9501331169+...". That takes a lot of time, especially for numbers like M521 and M607, in which case it can actually get very tiring. Last fiddled with by Stargate38 on 2014-04-19 at 00:13 Reason: More Info |
![]() |
![]() |
![]() |
#2 |
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2
22×32×7×37 Posts |
![]()
The answer is simple. There isn't always a program for anything one person in the world wants. Surprised? Well, in the world of billions of "apps" that seemingly can do almost anything (but at a second look are trivial as hell and yet want to get paid their $0.99), you might be. But it's true.
To give you an example, I cannot seem to find a bathroom seat that plays my favorite tune every time I seat on it. That makes me very sad. I'll probably have to order one from Japan. They take your vital measurements during the time of you bathroom visit, too. And there's a warmed up model. "Give a man a fish, and you feed him for a day; show him how to catch fish, and you feed him for a lifetime." So, there -- Learn to program, and write it! Learn perl and you will be able to write that program that you want in 15 seconds, and then when you will suddenly change you desire to also have a "Reverse, Add, and Reverse again program", you will write that one in 15 seconds, too. |
![]() |
![]() |
![]() |
#3 | |
"Kieren"
Jul 2011
In My Own Galaxy!
22·2,539 Posts |
![]() Quote:
|
|
![]() |
![]() |
![]() |
#4 |
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2
246C16 Posts |
![]()
"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett
|
![]() |
![]() |
![]() |
#5 |
"Kieren"
Jul 2011
In My Own Galaxy!
22×2,539 Posts |
![]() ![]() ![]() I know when I'm whupped. ![]() |
![]() |
![]() |
![]() |
#6 |
ἀβουλία
"Mr. Meeseeks"
Jan 2012
California, USA
32·241 Posts |
![]()
Damn. That was funny as hell.
![]() |
![]() |
![]() |
![]() |
#7 |
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2
246C16 Posts |
![]()
Well, I'd said A, and I've said B. It's time to say C.
Let me say a few words about that perl possible program. perl is convenient because it is, as the say, "for the rest of us". It is rather surprisingly fast if you think for a minute what it does invisibly under the hood for the user -- to make it look simple for him/her. On a very easy level, it does this: perl doesn't assume what the user wanted to say, for example, when a user input "92". Was it a number? Was it a text string? It creates and object that it is a text and a number (and other things but it is not important). So, because it is a text string, you can reverse it, with a function reverse() (the only other thing to know is that it will return an array, so you have scalar it), and you can also add or multiply it and/or the result because it is also a number. So with this preamble, let's type the program on the fly: Code:
#!/usr/bin/perl -w $in = $n = shift; while($n ne ($r = scalar reverse($n))) { $n += $r } print "$in ==> $n\n"; ./revandadd.pl 92 92 ==> 121 ./revandadd.pl 89 89 ==> 8813200023188 Easy, isn't it? For "196" input, though, you will get in trouble, and then you will start thinking about rewriting (or some fancy shmancy people would say refactoring) your initial idea. But the very beginning of the thinking process should be easy. And it is easy - with perl. |
![]() |
![]() |
![]() |
#8 | |
Bamboozled!
"𒉺𒌌𒇷𒆷𒀭"
May 2003
Down not across
3×3,529 Posts |
![]() Quote:
I'm guessing you can deal with Z80 assembly language ... Really --- writing one of these things is very nearly trivial. AFAIR, it was the first real Z80 code I ever wrote. |
|
![]() |
![]() |
![]() |
#9 |
"Daniel Jackson"
May 2011
14285714285714285714
641 Posts |
![]()
@Batalov: I get the following error when trying to use your script with the number 2147483647.
Code:
Argument "910+e79034420960716.9" isn't numeric in addition (+) at revandadd.pl line 4. |
![]() |
![]() |
![]() |
#10 |
"Mike"
Aug 2002
79·101 Posts |
![]()
Our lame attempt:
Code:
#!/bin/bash read a b=`echo $a | rev` echo $a+$b | bc | tr -d '\\\n' | sed 's/$/\n/' Code:
$ ./r 123 444 $ ./r 531137992816767098689588206552468627329593117727031923199444138200403559860852242739162502265229285668889329486246501015346579337652707239409519978766587351943831270835393219031728127 1252965123729160636761726555706254295209509022659739179933419781710509202545776231605745424827434547606131587555201805018178024328981837967120915902493451607546717257726160837331459262 |
![]() |
![]() |
![]() |
#11 |
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2
22·32·7·37 Posts |
![]()
Maybe it is, and maybe it isn't. By just running mindless computations you will not know it.
After 241,474 iterations, it reaches 100,000 digits After 2,415,564 iterations, it reaches 1,000,000 digits. Not that it will be useful to you, but here's another 15-minute scribble (obviously, not optimized and ugly) Code:
/* Reverse-and-Add */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define LIM 1000000 main(int argc,char **argv) { int i,L,eq, iter=0,cy; char *X; if(argc < 1) {printf("Use: %s number\n", argv[0]); exit(1);} L = strlen(argv[1])-1; if(L>=LIM) {printf(" %s : number is too long; recompile with higher LIM\n", argv[0]); exit(1);} X = malloc(LIM+2); for(i=0;i<=L;i++) { if(!isdigit(argv[1][i])) {printf(" %s : %s is not a decimal number\n", argv[0], argv[1]); exit(1);} X[L-i]=argv[1][i]-'0'; } while( L && !X[L] ) L--; // throw away zeroes, now L is the highest dit position while(L<LIM) { for(i=0,eq=1;i<=L/2;i++) if(X[i]!=X[L-i]) { eq=0; break; } if(eq) break; iter++; for(i=0;i<=L/2;i++) X[i]=X[L-i]=X[L-i]+X[i]; for(i=cy=0;i<=L;i++) if((X[i]+=cy)>=10) {cy=1; X[i]-=10;} else {cy=0;} if(cy) X[++L]=1; } for(i=0;i<=L;i++) X[i]+='0'; X[L+1]=0; if(eq) printf("%s ==> %s (iter=%d)\n", argv[1], X, iter); else printf("%s ... %s (iter=%d)\n", argv[1], X, iter); exit(0); } Code:
10 ==> 11 (iter=1) 11 ==> 11 (iter=0) 12 ==> 33 (iter=1) 13 ==> 44 (iter=1) 14 ==> 55 (iter=1) 15 ==> 66 (iter=1) 16 ==> 77 (iter=1) 17 ==> 88 (iter=1) 18 ==> 99 (iter=1) 19 ==> 121 (iter=2) 20 ==> 22 (iter=1) 21 ==> 33 (iter=1) 22 ==> 22 (iter=0) 23 ==> 55 (iter=1) 24 ==> 66 (iter=1) 25 ==> 77 (iter=1) 26 ==> 88 (iter=1) 27 ==> 99 (iter=1) 28 ==> 121 (iter=2) 29 ==> 121 (iter=1) 30 ==> 33 (iter=1) 31 ==> 44 (iter=1) 32 ==> 55 (iter=1) 33 ==> 33 (iter=0) 34 ==> 77 (iter=1) 35 ==> 88 (iter=1) 36 ==> 99 (iter=1) 37 ==> 121 (iter=2) 38 ==> 121 (iter=1) 39 ==> 363 (iter=2) 40 ==> 44 (iter=1) 41 ==> 55 (iter=1) 42 ==> 66 (iter=1) 43 ==> 77 (iter=1) 44 ==> 44 (iter=0) 45 ==> 99 (iter=1) 46 ==> 121 (iter=2) 47 ==> 121 (iter=1) 48 ==> 363 (iter=2) 49 ==> 484 (iter=2) 50 ==> 55 (iter=1) 51 ==> 66 (iter=1) 52 ==> 77 (iter=1) 53 ==> 88 (iter=1) 54 ==> 99 (iter=1) 55 ==> 55 (iter=0) 56 ==> 121 (iter=1) 57 ==> 363 (iter=2) 58 ==> 484 (iter=2) 59 ==> 1111 (iter=3) 60 ==> 66 (iter=1) 61 ==> 77 (iter=1) 62 ==> 88 (iter=1) 63 ==> 99 (iter=1) 64 ==> 121 (iter=2) 65 ==> 121 (iter=1) 66 ==> 66 (iter=0) 67 ==> 484 (iter=2) 68 ==> 1111 (iter=3) 69 ==> 4884 (iter=4) 70 ==> 77 (iter=1) 71 ==> 88 (iter=1) 72 ==> 99 (iter=1) 73 ==> 121 (iter=2) 74 ==> 121 (iter=1) 75 ==> 363 (iter=2) 76 ==> 484 (iter=2) 77 ==> 77 (iter=0) 78 ==> 4884 (iter=4) 79 ==> 44044 (iter=6) 80 ==> 88 (iter=1) 81 ==> 99 (iter=1) 82 ==> 121 (iter=2) 83 ==> 121 (iter=1) 84 ==> 363 (iter=2) 85 ==> 484 (iter=2) 86 ==> 1111 (iter=3) 87 ==> 4884 (iter=4) 88 ==> 88 (iter=0) 89 ==> 8813200023188 (iter=24) 90 ==> 99 (iter=1) 91 ==> 121 (iter=2) 92 ==> 121 (iter=1) 93 ==> 363 (iter=2) 94 ==> 484 (iter=2) 95 ==> 1111 (iter=3) 96 ==> 4884 (iter=4) 97 ==> 44044 (iter=6) 98 ==> 8813200023188 (iter=24) 99 ==> 99 (iter=0) 100 ==> 101 (iter=1) 101 ==> 101 (iter=0) 102 ==> 303 (iter=1) 103 ==> 404 (iter=1) 104 ==> 505 (iter=1) 105 ==> 606 (iter=1) 106 ==> 707 (iter=1) 107 ==> 808 (iter=1) 108 ==> 909 (iter=1) 109 ==> 1111 (iter=2) 110 ==> 121 (iter=1) 111 ==> 111 (iter=0) 112 ==> 323 (iter=1) 113 ==> 424 (iter=1) 114 ==> 525 (iter=1) 115 ==> 626 (iter=1) 116 ==> 727 (iter=1) 117 ==> 828 (iter=1) 118 ==> 929 (iter=1) 119 ==> 1331 (iter=2) 120 ==> 141 (iter=1) 121 ==> 121 (iter=0) 122 ==> 343 (iter=1) 123 ==> 444 (iter=1) 124 ==> 545 (iter=1) 125 ==> 646 (iter=1) 126 ==> 747 (iter=1) 127 ==> 848 (iter=1) 128 ==> 949 (iter=1) 129 ==> 1551 (iter=2) 130 ==> 161 (iter=1) 131 ==> 131 (iter=0) 132 ==> 363 (iter=1) 133 ==> 464 (iter=1) 134 ==> 565 (iter=1) 135 ==> 666 (iter=1) 136 ==> 767 (iter=1) 137 ==> 868 (iter=1) 138 ==> 969 (iter=1) 139 ==> 1771 (iter=2) 140 ==> 181 (iter=1) 141 ==> 141 (iter=0) 142 ==> 383 (iter=1) 143 ==> 484 (iter=1) 144 ==> 585 (iter=1) 145 ==> 686 (iter=1) 146 ==> 787 (iter=1) 147 ==> 888 (iter=1) 148 ==> 989 (iter=1) 149 ==> 1991 (iter=2) 150 ==> 303 (iter=2) 151 ==> 151 (iter=0) 152 ==> 707 (iter=2) 153 ==> 909 (iter=2) 154 ==> 1111 (iter=2) 155 ==> 4444 (iter=3) 156 ==> 6666 (iter=3) 157 ==> 8888 (iter=3) 158 ==> 11011 (iter=3) 159 ==> 1221 (iter=2) 160 ==> 343 (iter=2) 161 ==> 161 (iter=0) 162 ==> 747 (iter=2) 163 ==> 949 (iter=2) 164 ==> 2662 (iter=3) 165 ==> 4884 (iter=3) 166 ==> 45254 (iter=5) 167 ==> 88555588 (iter=11) 168 ==> 13431 (iter=3) 169 ==> 1441 (iter=2) 170 ==> 383 (iter=2) 171 ==> 171 (iter=0) 172 ==> 787 (iter=2) 173 ==> 989 (iter=2) 174 ==> 5115 (iter=4) 175 ==> 9559 (iter=4) 176 ==> 44044 (iter=5) 177 ==> 8836886388 (iter=15) 178 ==> 15851 (iter=3) 179 ==> 1661 (iter=2) 180 ==> 747 (iter=3) 181 ==> 181 (iter=0) 182 ==> 45254 (iter=6) 183 ==> 13431 (iter=4) 184 ==> 2552 (iter=3) 185 ==> 4774 (iter=3) 186 ==> 6996 (iter=3) 187 ==> 8813200023188 (iter=23) 188 ==> 233332 (iter=7) 189 ==> 1881 (iter=2) 190 ==> 45254 (iter=7) 191 ==> 191 (iter=0) 192 ==> 6996 (iter=4) 193 ==> 233332 (iter=8) 194 ==> 2992 (iter=3) 195 ==> 9339 (iter=4) 196 ... 76975401965800442861573399870479142798954446978100089780288777748516455290779635718553779119824043356725104534555389474375247021943775949210717459646532038439584612391814396648322000858192801202979037723409954008178044168534263086394415445029227777175975220039022178644377310675604518574251631379819073576113627782023104096657096516303809741844064556374656810458531715852460140138838161919704270044261539772831948177103162135907319445890822350363810973599251443517726598399709502756009018217284645796686557472801910999568204808003806517715444252885488027362064119197455803710522252301781740227377926162450062497018172739830942064159407146754919645474645570437246909403515591855601400231286626411764470018973136142475826405575122773546871219841011579572866723030445404493790253535752431961899360993437729879213097391848011213935703417203126386043741136636053727903059567340220642583365082556425510428743439339911966365717547977091563526737788782977980001988644450888242963188883376158254998668014589571 (iter=2393) 197 ==> 881188 (iter=7) 198 ==> 79497 (iter=5) 199 ==> 3113 (iter=3) 200 ==> 202 (iter=1) Last fiddled with by Batalov on 2014-04-19 at 22:20 Reason: (not replying to Mike's crosspost, obviously) |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Find the Value | davar55 | Puzzles | 25 | 2007-07-15 15:56 |
New way to Find (X^Y) % M | maheshexp | Software | 2 | 2004-05-08 03:16 |
Where I find the best program to it factor keys? I use AMD. | chrow | Factoring | 5 | 2004-02-19 10:15 |
Reverse Decomp Program | nfortino | LMH > 100M | 2 | 2004-01-30 22:38 |
I want to use my own program to find.... | Unregistered | Software | 4 | 2003-12-06 20:47 |