mersenneforum.org  

Go Back   mersenneforum.org > Math Stuff > Computer Science & Computational Number Theory > PARI/GP

Reply
 
Thread Tools
Old 2010-12-05, 01:48   #2003
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
This sounds too hard, too many things to look for.
It's pretty easy in a language like Perl, where the answer (for Pari!) would be a single, short line. But Pari has almost no string-manipulation functions, so it's rather hard to do there.
CRGreathouse is offline   Reply With Quote
Old 2010-12-05, 01:49   #2004
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

http://rosettacode.org/wiki/LZW_compression is described both on wikipedia and a book I own. Doesn't sound too hard, Of course I said that about most things lol.
science_man_88 is offline   Reply With Quote
Old 2010-12-05, 02:10   #2005
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Go for it, then.
CRGreathouse is offline   Reply With Quote
Old 2010-12-05, 02:15   #2006
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Go for it, then.
according to my book it doesn't concat anything into the library/dictionary until it hits it the second time in a string, also it talks of a simplified case of all upcase I'll have to make the starting dictionary twice as long for both cases and 52 variables to track them through 2 times i guess I must be over complicating things, doh.
science_man_88 is offline   Reply With Quote
Old 2010-12-05, 02:30   #2007
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Maybe try something easier first, then? Perhaps

http://rosettacode.org/wiki/Non-decimal_radices/Input
or
http://rosettacode.org/wiki/Write_fl...to_a_text_file
CRGreathouse is offline   Reply With Quote
Old 2010-12-05, 13:33   #2008
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Maybe try something easier first, then? Perhaps

http://rosettacode.org/wiki/Non-decimal_radices/Input
My plan for this is no less complex now.



1)Create 2, 36 index vectors then shorten them for the respective bases.
2)Read a Vec of the number to convert and use the index to add into a decimal form variable.
3)take that decimal form and use variable%b2 to get each index to return later.
4) return it.
science_man_88 is offline   Reply With Quote
Old 2010-12-05, 13:56   #2009
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

trouble on number 1)

Code:
***   syntax error, unexpected ',': ...mb1,b1,b2)=b1digs["0","1","2","3","4","5","6"
                                                                ^--------------------
never mind forgot the equals sign.

Last fiddled with by science_man_88 on 2010-12-05 at 13:57
science_man_88 is offline   Reply With Quote
Old 2010-12-05, 15:11   #2010
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

Wow. I see we've collected 2000 posts.
3.14159 is offline   Reply With Quote
Old 2010-12-05, 15:14   #2011
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Wow. I see we've collected 2000 posts.
I bet if we took out all of the useless ones we'd not even have half that lol.

Code:
convert(numb1,b1,b2)= b1digs=["0","1","2","3","4","5","6","7","8","9","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"];b1digs=vector(b1,n,b1digs[n]);b2digs=["0","1","2","3","4","5","6","7","8","9","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"];b2digs=vector(b2,n,b2digs[n]);numb1=Vec(Str(numb1));a=0;c=[];forstep(y=#numb1,1,-1,for(x=1,#b1digs,if(numb1[y]==b1digs[x],a=a+(x-1)*b1^(#numb1-y))));until(floor(a/b2)==0,c=concat(b2digs[a%b2+1],c));c;
most useless Pari code ever lol.
science_man_88 is offline   Reply With Quote
Old 2010-12-05, 16:09   #2012
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

10111010110112 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
Code:
convert(numb1,b1,b2)= b1digs=["0","1","2","3","4","5","6","7","8","9","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"];b1digs=vector(b1,n,b1digs[n]);b2digs=["0","1","2","3","4","5","6","7","8","9","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"];b2digs=vector(b2,n,b2digs[n]);numb1=Vec(Str(numb1));a=0;c=[];forstep(y=#numb1,1,-1,for(x=1,#b1digs,if(numb1[y]==b1digs[x],a=a+(x-1)*b1^(#numb1-y))));until(floor(a/b2)==0,c=concat(b2digs[a%b2+1],c));c;
most useless Pari code ever lol.
You're defining the same (long) vector twice; why not avoid that?
Code:
convert(numb1,b1,b2)={
  my(B=["0","1","2","3","4","5","6","7","8","9","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"],b1digs=vector(b1,n,B[n]),b2digs=vector(b2,n,B[n]),a=0,c=[]);
  numb1=Vec(Str(numb1));
  forstep(y=#numb1,1,-1,
    for(x=1,#b1digs,
      if(numb1[y]==b1digs[x],
        a=a+(x-1)*b1^(#numb1-y)
      )
    )
  );
  until(floor(a/b2)==0,
    c=concat(b2digs[a%b2+1],c)
  );
  c
};
It looks like you could avoid using both b1digs and b2digs by simply pulling from the general vector B each time. Usual comments on a = a + foo vs. a += foo and floor(a/foo) vs. a\foo appy.
CRGreathouse is offline   Reply With Quote
Old 2010-12-05, 16:12   #2013
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
You're defining the same (long) vector twice; why not avoid that?
Code:
convert(numb1,b1,b2)={
  my(B=["0","1","2","3","4","5","6","7","8","9","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"],b1digs=vector(b1,n,B[n]),b2digs=vector(b2,n,B[n]),a=0,c=[]);
  numb1=Vec(Str(numb1));
  forstep(y=#numb1,1,-1,
    for(x=1,#b1digs,
      if(numb1[y]==b1digs[x],
        a=a+(x-1)*b1^(#numb1-y)
      )
    )
  );
  until(floor(a/b2)==0,
    c=concat(b2digs[a%b2+1],c)
  );
  c
};
It looks like you could avoid using both b1digs and b2digs by simply pulling from the general vector B each time. Usual comments on a = a + foo vs. a += foo and floor(a/foo) vs. a\foo appy.
apply* only if you only go up to index b1, or b2 for each.
science_man_88 is offline   Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do I sometimes see all the <> formatting commands when I quote or edit? cheesehead Forum Feedback 3 2013-05-25 12:56
Passing commands to PARI on Windows James Heinrich Software 2 2012-05-13 19:19
Ubiquity commands Mini-Geek Aliquot Sequences 1 2009-09-22 19:33
64-bit Pari? CRGreathouse Software 2 2009-03-13 04:22
Are these commands correct? jasong Linux 2 2007-10-18 23:40

All times are UTC. The time now is 22:43.


Fri Aug 6 22:43:27 UTC 2021 up 14 days, 17:12, 1 user, load averages: 4.78, 4.24, 3.78

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.