mersenneforum.org  

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

Reply
 
Thread Tools
Old 2010-12-01, 16:03   #1849
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
Yeah same with comment(s) like they say no passwords in plain text you may get lost trying to read uncommented code, But some random other person could have just as hard of a time until they figure it out.
"No passwords in plain text" has nothing to do with comments in source code.
CRGreathouse is offline   Reply With Quote
Old 2010-12-01, 16:06   #1850
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

My encode of rle isn't perfect for example:

RLE(hello world) = 1H1e2l1o1w1o1r1l1d

RLE("Hello world") = 1H1e2l1o101w1o1r1l1d

so they don't code out the same and so my decode will likely have to compensate unless my encode is redone.
science_man_88 is offline   Reply With Quote
Old 2010-12-01, 16:59   #1851
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Code:
(12:54) gp > checkstring(string) = eval(vector(Vec(Str(string))))
%90 = (string)->eval(vector(Vec(Str(string))))
(12:56) gp > checkstring(string)
  *** vector: gtos expected an integer, got '["s", "t", "r", "i", "n", "g"]'.
catch the error and you complete http://rosettacode.org/wiki/Determin...ing_is_numeric no ?

actually maybe not you'd have to check if it's not a number list, Oh well my mistake again...

Last fiddled with by science_man_88 on 2010-12-01 at 17:01
science_man_88 is offline   Reply With Quote
Old 2010-12-01, 17:18   #1852
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
My encode of rle isn't perfect for example:

RLE(hello world) = 1H1e2l1o1w1o1r1l1d

RLE("Hello world") = 1H1e2l1o101w1o1r1l1d

so they don't code out the same and so my decode will likely have to compensate unless my encode is redone.
Solution: Don't ever, ever, ever pass strings without quoting them. If you do, you're going to end up with nonsense like this where your first example omits the space.

Passing strings without quotes causes serious issues and does not work in all cases. Don't do it. (When you do this, what's actually happening is you're sending monomials which are evaluated to their own names (!), but if a values becomes associated you'll see that instead of what you wanted.)

Your improper use of eval() caused the space to be read as 0 rather than as a space.
CRGreathouse is offline   Reply With Quote
Old 2010-12-01, 17:21   #1853
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
Code:
(12:54) gp > checkstring(string) = eval(vector(Vec(Str(string))))
%90 = (string)->eval(vector(Vec(Str(string))))
(12:56) gp > checkstring(string)
  *** vector: gtos expected an integer, got '["s", "t", "r", "i", "n", "g"]'.
To check the type of a variable, look at type(variable). If it's a string the type will be "t_STR".

type(0) is t_INT
type(1/2) is t_FRAC
type(x^3 + 1) is t_POL
type(x) is t_POL
type(hello) is t_POL
type("hello") is t_STR
and so forth.
CRGreathouse is offline   Reply With Quote
Old 2010-12-01, 17:23   #1854
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Code:
(13:18) gp > for(x=1,10,print1(x);if(x!=10,print1(",")))
1,2,3,4,5,6,7,8,9,10
(13:18) gp > for(x=1,10,print1(x);if(x==10,break());print1(","))
1,2,3,4,5,6,7,8,9,10
(13:19) gp > for(x=1,9,print1(x);print1(","));print(10)
1,2,3,4,5,6,7,8,9,10
(13:20) gp > for(x=1,9,print1(x","));print(10)
1,2,3,4,5,6,7,8,9,10
not sure which implementation is best for http://rosettacode.org/wiki/Loops/N_plus_one_half lol
science_man_88 is offline   Reply With Quote
Old 2010-12-01, 17:25   #1855
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

http://rosettacode.org/wiki/Pattern_matching

right up my alley just not sure what i want to do for it.
science_man_88 is offline   Reply With Quote
Old 2010-12-01, 17:26   #1856
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
Code:
(13:18) gp > for(x=1,10,print1(x);if(x!=10,print1(",")))
1,2,3,4,5,6,7,8,9,10
(13:18) gp > for(x=1,10,print1(x);if(x==10,break());print1(","))
1,2,3,4,5,6,7,8,9,10
(13:19) gp > for(x=1,9,print1(x);print1(","));print(10)
1,2,3,4,5,6,7,8,9,10
(13:20) gp > for(x=1,9,print1(x","));print(10)
1,2,3,4,5,6,7,8,9,10
not sure which implementation is best for http://rosettacode.org/wiki/Loops/N_plus_one_half lol
I've given some thought to that myself. I think to go with the spirit of the problem a while(1, ...) loop might be best.
CRGreathouse is offline   Reply With Quote
Old 2010-12-01, 17:30   #1857
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
I've given some thought to that myself. I think to go with the spirit of the problem a while(1, ...) loop might be best.
unless a while has a otherwise do this part it wouldn't all be in the loop and:

Quote:
Quite often one needs loops which, in the last iteration, execute only part of the loop body. The goal of this task is to demonstrate the best way to do this.
Write a loop which writes the comma-separated list
suggest it should be part of the loop which knocks out all but the first 2 in my group, as well as possibly a while, or do until.

never mind dah if statements lol.

Last fiddled with by science_man_88 on 2010-12-01 at 17:46
science_man_88 is offline   Reply With Quote
Old 2010-12-01, 17:54   #1858
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

135338 Posts
Default

I can't quite follow you, but
Code:
n=0;
while(1,
  print1(n++);
  if(n>9, break);
  print1(", ")
);
does the trick.
CRGreathouse is offline   Reply With Quote
Old 2010-12-01, 17:56   #1859
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
To check the type of a variable, look at type(variable). If it's a string the type will be "t_STR".

type(0) is t_INT
type(1/2) is t_FRAC
type(x^3 + 1) is t_POL
type(x) is t_POL
type(hello) is t_POL
type("hello") is t_STR
and so forth.
so in other words if(string==type(0) ||string==type(1/2), print("this string is numerical")) would work ? Though I haven't covered floating point types.
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:59.


Fri Aug 6 22:59:28 UTC 2021 up 14 days, 17:28, 1 user, load averages: 4.09, 4.16, 4.02

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.