![]() |
[QUOTE=science_man_88;240062]This sounds too hard, too many things to look for.[/QUOTE]
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. |
[url]http://rosettacode.org/wiki/LZW_compression[/url] is described both on wikipedia and a book I own. Doesn't sound too hard, Of course I said that about most things lol.
|
Go for it, then.
|
[QUOTE=CRGreathouse;240067]Go for it, then.[/QUOTE]
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. |
Maybe try something easier first, then? Perhaps
[url]http://rosettacode.org/wiki/Non-decimal_radices/Input[/url] or [url]http://rosettacode.org/wiki/Write_float_arrays_to_a_text_file[/url] |
[QUOTE=CRGreathouse;240069]Maybe try something easier first, then? Perhaps
[url]http://rosettacode.org/wiki/Non-decimal_radices/Input[/url][/QUOTE] 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. |
trouble on number 1)
[CODE][COLOR="Red"]*** syntax error, unexpected ',': ...mb1,b1,b2)=b1digs["0","1","2","3","4","5","6" ^--------------------[/COLOR][/CODE] never mind forgot the equals sign. |
Wow. I see we've collected 2000 posts.
|
[QUOTE=3.14159;240117]Wow. I see we've collected 2000 posts.[/QUOTE]
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;[/CODE] most useless Pari code ever lol. |
[QUOTE=science_man_88;240119][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;[/CODE]
most useless Pari code ever lol.[/QUOTE] 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 };[/CODE] 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. |
[QUOTE=CRGreathouse;240131]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 };[/CODE] 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.[/QUOTE] apply* only if you only go up to index b1, or b2 for each. |
| All times are UTC. The time now is 23:07. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.