![]() |
Suppressing exceptions:
never played with try and catch so never caught an error in my code to suppress lol. |
Storing secrets in plain text
good luck i don't even make addhelp for most of my programs in Pari lol, I'm not necessarily going to leave something as a comment lol. |
Not being up to date:
probably my second worst one. my number 1 might be #1 lol |
[QUOTE=science_man_88;239474]Suppressing exceptions:
never played with try and catch so never caught an error in my code to suppress lol.[/QUOTE] Yes, by doing nothing you have actually been doing it the right way. :smile: Having said that, trap() is occasionally useful. |
[QUOTE=CRGreathouse;239477]Yes, by doing nothing you have actually been doing it the right way. :smile:
Having said that, trap() is occasionally useful.[/QUOTE] Yeah same with comment(s) like they say [COLOR="Red"]no passwords in plain text[/COLOR] 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. |
[QUOTE=science_man_88;239480]Yeah same with comment(s) like they say [COLOR="Red"]no passwords in plain text[/COLOR] 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.[/QUOTE]
"No passwords in plain text" has nothing to do with comments in source code. |
My encode of rle isn't perfect for example:
RLE(hello world) = 1H1e2l1o1w1o1r1l1d RLE("Hello world") = 1H1e2l1o[COLOR="Red"]10[/COLOR]1w1o1r1l1d so they don't code out the same and so my decode will likely have to compensate unless my encode is redone. |
[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"]'.[/CODE] catch the error and you complete [url]http://rosettacode.org/wiki/Determine_if_a_string_is_numeric[/url] no ? actually maybe not you'd have to check if it's not a number list, Oh well my mistake again... |
[QUOTE=science_man_88;239482]My encode of rle isn't perfect for example:
RLE(hello world) = 1H1e2l1o1w1o1r1l1d RLE("Hello world") = 1H1e2l1o[COLOR="Red"]10[/COLOR]1w1o1r1l1d so they don't code out the same and so my decode will likely have to compensate unless my encode is redone.[/QUOTE] 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. |
[QUOTE=science_man_88;239491][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"]'.[/CODE][/QUOTE] 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. |
[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[/CODE] not sure which implementation is best for [url]http://rosettacode.org/wiki/Loops/N_plus_one_half[/url] lol |
[url]http://rosettacode.org/wiki/Pattern_matching[/url]
right up my alley just not sure what i want to do for it. |
[QUOTE=science_man_88;239498][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[/CODE] not sure which implementation is best for [url]http://rosettacode.org/wiki/Loops/N_plus_one_half[/url] lol[/QUOTE] 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. |
[QUOTE=CRGreathouse;239501]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.[/QUOTE]
unless a while has a otherwise do this part it wouldn't all be in the loop and: [QUOTE]Quite often one needs [B]loops[/B] which, in the [B]last iteration[/B], execute only [B]part of the loop[/B] body. The goal of this task is to demonstrate the best way to do this. Write a loop which writes the comma-separated list[/QUOTE] 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. |
I can't quite follow you, but
[code]n=0; while(1, print1(n++); if(n>9, break); print1(", ") );[/code] does the trick. |
[QUOTE=CRGreathouse;239497]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.[/QUOTE] 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. |
[QUOTE=CRGreathouse;239504]I can't quite follow you, but
[code]n=0; while(1, print1(n++); if(n>9, break); print1(", ") );[/code] does the trick.[/QUOTE] Wonder how fast we could finish off the list? You know most of them by the sounds of it. I'm still a little stumped on how to fix my rle script but I know ( and ) shouldn't be used to code something with. By the looks of it and I need ways to check for control characters,spaces and numbers that appear out of nowhere in the strings but aren't part of the count of characters) maybe a Vec, and a scan of type will do but maybe not. I'm so stupid maybe tab in between would help lol. |
if something can be done to files in the file system root:
[url]http://rosettacode.org/wiki/File_size[/url] the hard part to this one that must have landed it in the too hard category must be how to read the original given file size to compare something with. |
[url]http://rosettacode.org/wiki/Pascal's_triangle/Puzzle[/url]
Doesn't sound hard in one sense. solve: [QUOTE] [CENTER] [ 151] [ ][ ] [40][ ][ ] [ ][ ][ ][ ] [ X][11][ Y][ 4][ Z][/CENTER][/QUOTE] first piece I can gather is x+y+22 = 40;so x+y=18 this is a fact to check for; also once a pair of x and y =18; also x+2y+z+30 = 151; so x+2y+z = 121; another fact to check for when going through z values. |
[CODE]for(x=0,18,for(y=0,18,if(x+y=18,for(z=1,103,if((x+2*y+z)==121,print(x","y","z);break(3))))))[/CODE]
First one it found was 0,18,85 . It never says the program has to use only the data given, I used what I could gather. |
[QUOTE=science_man_88;239513][CODE]for(x=0,18,for(y=0,18,if(x+y=18,for(z=1,103,if((x+2*y+z)==121,print(x","y","z);break(3))))))[/CODE]
First one it found was 0,18,85 . It never says the program has to use only the data given, I used what I could gather.[/QUOTE] oops forgot y=x+z but that doesn't work I've messed up |
I've determined y=13 by:
[ 6y+x+z+4a[2]+4a[4]= 7y +4a[2]+4a[4]] [3y+x+37 ][3y+z+23] [40=x+y+22][ 2y+15][ y+z+8 ] [ x+11 ][y+11 ][y+4 ][z+4 ] [ X][11][ Y][ 4][ Z] if a = [] bottom row for this sized triangle we see in this case 151-(44+16) = 91 ; 91/7 =13 y=13 40-13-22 =x = 5; 13-5=z=8; however I now know how to solve it in this case. |
[CODE] Pascals_triangle_puzzle(topvalue=151,leftsidevalue=40,bottomvalue1=11,bottomvalue2=4) = {
y=(topvalue-(4*(bottomvalue1+bottomvalue2)))/7; x=leftsidevalue-(y+2*bottomvalue1); z=y-x; print(x","y","z); }[/CODE] This easy enough ? I might try to make one for any size. just have to figure out the patterns lol. |
I figured out how to falsify factoring a large number (somewhat);
[code][866876601688257388041953428681474799611455578456879011971315052706094788178469895182220494116473202297231530219967803566778120639 528365543601153323389150907773258262552994601295053933845142213535320241754514748728875053183803012869853716977772216817067444377] [361704130063529693429159107448019863732305480622816041454555619831169499041663864963068219490947259594777674878198147873998732309 326729818580681541350657067987755793696856969106820654842683490163988042729198926945304899046855890448333533668661395285070725039][/code] Which is.. [code]866876601688257388041953428681474799611455578456879011971315052706094788178469895182220494116473202297231530219967803566778120639[sup]528365543601153323389150907773258262552994601295053933845142213535320241754514748728875053183803012869853716977772216817067444377[/sup] * 361704130063529693429159107448019863732305480622816041454555619831169499041663864963068219490947259594777674878198147873998732309[sup]326729818580681541350657067987755793696856969106820654842683490163988042729198926945304899046855890448333533668661395285070725039[/sup][/code] |
[QUOTE=3.14159;239539]I figured out how to falsify factoring a large number (somewhat);
[code][866876601688257388041953428681474799611455578456879011971315052706094788178469895182220494116473202297231530219967803566778120639 528365543601153323389150907773258262552994601295053933845142213535320241754514748728875053183803012869853716977772216817067444377] [361704130063529693429159107448019863732305480622816041454555619831169499041663864963068219490947259594777674878198147873998732309 326729818580681541350657067987755793696856969106820654842683490163988042729198926945304899046855890448333533668661395285070725039][/code] Which is.. [code]866876601688257388041953428681474799611455578456879011971315052706094788178469895182220494116473202297231530219967803566778120639[sup]528365543601153323389150907773258262552994601295053933845142213535320241754514748728875053183803012869853716977772216817067444377[/sup] * 361704130063529693429159107448019863732305480622816041454555619831169499041663864963068219490947259594777674878198147873998732309[sup]326729818580681541350657067987755793696856969106820654842683490163988042729198926945304899046855890448333533668661395285070725039[/sup][/code][/QUOTE] finally Pi is back lol. |
[QUOTE=science_man_88;239540]finally Pi is back lol.[/QUOTE]
Thanks. I get + 1 years added to my current age today. |
[QUOTE=science_man_88;239506]so in other words if(string==type(0) ||string==type(1/2), print("this string is numerical")) would work ?[/QUOTE]
No. if(type(string) == "t_STR", print("It's a string.")) [QUOTE=science_man_88;239506]Though I haven't covered floating point types.[/QUOTE] t_REAL and t_COMPLEX. |
[QUOTE=3.14159;239539]I figured out how to falsify factoring a large number (somewhat)[/QUOTE]
Getting there. As it happens that could never be the output of factor() for at least two reasons. (Can you guess either?) |
[QUOTE=3.14159;239541]Thanks. I get + 1 years added to my current age today.[/QUOTE]
Beginning programmer: piage = piage + 1; sm: piAge += 1; me: pi.age++; |
[QUOTE=CRGreathouse;239543]Getting there. As it happens that could never be the output of factor() for at least two reasons. (Can you guess either?)[/QUOTE]
1. Far too large. 2. Takes too long. |
[QUOTE=CRGreathouse;239543]Getting there. As it happens that could never be the output of factor() for at least two reasons. (Can you guess either?)[/QUOTE]
1) the factors look familiar ( like the bases of the exponents to me) 2) because factor() uses prime factors and exponents but only the base is listed ? |
[QUOTE=science_man_88;239547]1) the factors look familiar ( like the bases of the exponents to me)
2) because factor() uses prime factors and exponents but only the base is listed ?[/QUOTE] 2) is incorrect. Both primes and exponents are listed. |
[QUOTE=3.14159;239545]1. Far too large.
2. Takes too long.[/QUOTE] Those look like arguments that it couldn't reasonably appear, but I meant 'not even if there was lots of time', say 2^500 seconds. :smile: (Good try, though!) |
[QUOTE=CRGreathouse;239544]Beginning programmer:
piage = piage + 1; sm: piAge += 1; me: pi.age++;[/QUOTE] I'm guessing the last one is C? |
[QUOTE=3.14159;239550]I'm guessing the last one is C?[/QUOTE]
They are, respectively, GP, GP, and GP. |
[QUOTE=CRGreathouse;239549]Those look like arguments that it couldn't reasonably appear, but I meant 'not even if there was lots of time', say 2^500 seconds. :smile:
(Good try, though!)[/QUOTE] And, those numbers would be too large to even handle, let alone make some computations with, and they're not in order from least to greatest. |
[QUOTE=CRGreathouse;239551]They are, respectively, GP, GP, and GP.[/QUOTE]
O rly? |
[url]http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_PARI/GP[/url]
Is what we've been trying to clear Pi. |
[QUOTE=3.14159;239550]I'm guessing the last one is C?[/QUOTE]
CRG there's a period breaking the name is that normal ? |
[QUOTE=science_man_88;239554][url]http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_PARI/GP[/url]
Is what we've been trying to clear Pi.[/QUOTE] I think PARI/GP's too weak for those tasks. |
[QUOTE=3.14159;239556]I think PARI/GP's too weak for those tasks.[/QUOTE]
I tried a bunch I've cleared 5 with help and 2 CRG has pretty much rewritten they aren't impossible lol should i point to the ones I've tried ? this would include part of a RLE script,guess number/with feedback ( just saw a message about how long the code is per line I must format it "properly",Pascals triangle, the "Pascals triangle/ puzzle", a lousy rate counter, I've tried loop N + 1/2, and asked about why stack was on the list still and brought up some I think we can finish like the tower of Hanoi ( involves Mersenne numbers for fastest solve). |
[QUOTE=3.14159;239552]And, those numbers would be too large to even handle, let alone make some computations with, and they're not in order from least to greatest.[/QUOTE]
Ding ding! Pi wins. |
[QUOTE=science_man_88;239557]I tried a bunch I've cleared 5 with help and 2 CRG has pretty much rewritten they aren't impossible lol should i point to the ones I've tried ? this would include part of a RLE script,guess number/with feedback ( just saw a message about how long the code is per line I must format it "properly",Pascals triangle, the "Pascals triangle/ puzzle", a lousy rate counter, I've tried loop N + 1/2, and asked about why stack was on the list still and brought up some I think we can finish like the tower of Hanoi ( involves Mersenne numbers for fastest solve).[/QUOTE]
I think that another one that may be partially possible is the challenge of creating a script that would evaluate arithmetic expressions, such as "(5^2 + 7) + 41", without using the built-in calculator. How the lottery should be; 1. 100 numbers are randomly given to you. 2. Arrange these numbers in a certain order (not given) 3. Winner gets $(10^10). |
[QUOTE=3.14159;239559]I think that another one that may be partially possible is the challenge of creating a script that would evaluate arithmetic expressions, such as "(5^2 + 7) + 41", without using the built-in calculator.[/QUOTE]
[CODE]evalscript(script) = eval(script)[/CODE] ? or [CODE]evalscript(script) = eval(Vec(Str(script)))[/CODE] |
[QUOTE=3.14159;239553]O rly?[/QUOTE]
[QUOTE=science_man_88;239555]CRG there's a period breaking the name is that normal ?[/QUOTE] Ah, good for you for noticing! No, periods aren't allowed in names. What's going on here is that I define pi as a variable, say [CODE]pi=["Kevin", "3.14159", 42, 0, 0];[/CODE] then I define the function [CODE]x.age={ if (type(x) != "t_VEC" || #x != 5, error("Type error")); x[3] };[/CODE] so that pi.age returns pi's age. (Forgive the [i]Hitchhiker's Guide to the Galaxy[/i] reference; I don't know his real age.) |
[QUOTE=3.14159;239559]I think that another one that may be partially possible is the challenge of creating a script that would evaluate arithmetic expressions, such as "(5^2 + 7) + 41", without using the built-in calculator.[/QUOTE]
[QUOTE=science_man_88;239560][CODE]evalscript(script) = eval(script)[/CODE] ? or [CODE]evalscript(script) = eval(Vec(Str(script)))[/CODE][/QUOTE] Not allowed, see the problem description. |
[QUOTE=CRGreathouse;239561]Ah, good for you for noticing!
No, periods aren't allowed in names. What's going on here is that I define pi as a variable, say [CODE]pi=["Kevin", "3.14159", 42, 0, 0];[/CODE] then I define the function [CODE]x.age={ if (type(x) != "t_VEC" || #x != 5, error("Type error")); x[3] };[/CODE] so that pi.age returns pi's age. (Forgive the [i]Hitchhiker's Guide to the Galaxy[/i] reference; I don't know his real age.)[/QUOTE] I'm 42 * 0.380952380952380952380952381... |
[QUOTE=3.14159;239565]I'm 42 * 0.380952380952380952380952381...[/QUOTE]
Wow, that's a lot of decimal places. Can we assume you were born at 7:19:00.00000000000000000006 PM, then? :razz: Actually I learned something from my pi.age example: I had thought that member functions (somehow) returned lvalues, but it looks like they just give ordinary rvalues. As a result you can't actually do pi.age++. |
you know how you can load the file on runtime with the functions ?
can you do the same but call a function on runtime ? if so Create a two-dimensional array at runtime is doable with that just make a useless function that creates the array. |
[QUOTE=CRGreathouse;239564]Not allowed, see the problem description.[/QUOTE]
How about we simply apply the iterative definition? Start with a. a + 1 Let a + b = a + 1 + 1 + 1 + 1 + 1 + 1 + 1.... Let a * b = a + a + a + a + a + a + a + a + a + .... Let a^b = a * a * a * a * a * a.. Etc. |
[QUOTE=CRGreathouse;239566]Wow, that's a lot of decimal places. Can we assume you were born at 7:19:00.00000000000000000006 PM, then? :razz:
Actually I learned something from my pi.age example: I had thought that member functions (somehow) returned lvalues, but it looks like they just give ordinary rvalues. As a result you can't actually do pi.age++.[/QUOTE] Actually, I was born at 2:45 AM, on a Thursday. |
[url]http://rosettacode.org/wiki/Palindrome_detection[/url]
I think i have a way to do this: 1) create a Vec with the string 2) call a loop to check if v[i] and v[#v-i] or something like that if 1 based array to check if it's the same if so for all the ones around the center it proves it's a palindrome if I remember my definitions lol. |
All that would have to be done to follow that nice iterative process would be to define a + 1.
Or would that also be disallowed? There would also be the problem of the opposites of those; a - 1, a - b, a/b, a^(1/b), etc. |
[QUOTE=3.14159;239556]I think PARI/GP's too weak for those tasks.[/QUOTE]
It is for some -- listed at [url]http://rosettacode.org/wiki/Category:PARI/GP/Omit[/url] though you're welcome to try even those if you have a mind to. I put most of those there because Pari would be bad at them, but in some cases it's literally incapable of doing them without system() or extern() or the like. But for many of the tasks Pari is well-suited. |
[QUOTE=science_man_88;239568]Create a two-dimensional array at runtime[/QUOTE]
I don't remember that problem description off the top of my head, but isn't that easy to do with matrix()? |
[QUOTE=3.14159;239569]How about we simply apply the iterative definition?
Start with a. a + 1 Let a + b = a + 1 + 1 + 1 + 1 + 1 + 1 + 1.... Let a * b = a + a + a + a + a + a + a + a + a + .... Let a^b = a * a * a * a * a * a.. Etc.[/QUOTE] It's not at all clear how you'd code this. (Yes, I know of a way to code it, but I'm not sure that it's related to what you're saying.) And wouldn't that method be slow? If 2^1000 expands out into the (2^1000 - 1)-times-iterated successor of 1, it will take at least 2^1000 - 1 steps to compute... |
[QUOTE=CRGreathouse;239576]It's not at all clear how you'd code this. (Yes, I know of a way to code it, but I'm not sure that it's related to what you're saying.) And wouldn't that method be slow? If 2^1000 expands out into the (2^1000 - 1)-times-iterated successor of 1, it will take at least 2^1000 - 1 steps to compute...[/QUOTE]
A solution would be to make each into its own operator, so the expansion of 2^1000 into 1 + 1 + 1 + 1 + 1 + 1 + 1 + ... (2^1000 terms) is avoided. a + 1, a + b, a * b, a^b should be independent of each other. Albeit, I think I would have to defy the rule and use the built-in calculator. |
[QUOTE=3.14159;239577]A solution would be to make each into its own operator, so the expansion of 2^1000 into 1 + 1 + 1 + 1 + 1 + 1 + 1 + ... (2^1000 terms) is avoided.[/QUOTE]
But if the exponentiation function calls the multiplication function, and the multiplication function calls the addition function, and the addition function calls the successor function, then you will have a total of 2^1000 - 1 calls to the successor function unless you memoize the results (etc.). |
[QUOTE=CRGreathouse;239575]I don't remember that problem description off the top of my head, but isn't that easy to do with matrix()?[/QUOTE]
oh I read the done list lol. |
[CODE]palindrome(string) ={
my(string=eval(Vec(Str(string)))); for(x=1,ceil(#string/2), if(string[x]!=string[#string-(x-1)], break(), print(string) ) ); } [/CODE] CRG approval ? |
[QUOTE=science_man_88;239583]CRG approval ?[/QUOTE]
Close. :smile: You should return 1 if the string is a palindrome and a 0 otherwise. (If you just print, you can't use the results anywhere!) There are nitpicks (you should only do the eval/Vec/Str thing if you're starting with an integer, just use Vec otherwise, no need for my since the variable string is already local, you can round down [and this use \2] since the middle character, if any, is always equal to itself) but those don't really matter, that's just taking it to the next level. |
[QUOTE=CRGreathouse;239584]Close. :smile:
You should return 1 if the string is a palindrome and a 0 otherwise. (If you just print, you can't use the results anywhere!) There are nitpicks (you should only do the eval/Vec/Str thing if you're starting with an integer, just use Vec otherwise, no need for my since the variable string is already local, you can round down [and this use \2] since the middle character, if any, is always equal to itself) but those don't really matter, that's just taking it to the next level.[/QUOTE] .. How about Python? It could certainly do more tasks, IMO, although not necessarily math-related. Something that would be nice for Python would be to be able to make a short script to do a primality proof in it. (Special-form primes, preferably, for general primes, use a PRP.) |
[QUOTE=CRGreathouse;239584]Close. :smile:
You should return 1 if the string is a palindrome and a 0 otherwise. (If you just print, you can't use the results anywhere!) There are nitpicks (you should only do the eval/Vec/Str thing if you're starting with an integer, just use Vec otherwise, no need for my since the variable string is already local, you can round down [and this use \2] since the middle character, if any, is always equal to itself) but those don't really matter, that's just taking it to the next level.[/QUOTE] I knew the return part was coming lol. yeah I did the eval(Vec(Str())) because I don't know what type they enter so unless I do a check for each type it's easier that way. I used ceil() because my formula wouldn't work without it that way so it's either change the formula or the function I use. |
[QUOTE=3.14159;239586].. How about Python?
It could certainly do more tasks, IMO, although not necessarily math-related.[/QUOTE] Sure, it's a general-purpose programming language. I don't use it much myself (I use C, JavaScript, Pari, SQL, Perl, and C# more often) but it's not a bad language. I'm not sure exactly what you're asking about it. |
[QUOTE=CRGreathouse;239588]Sure, it's a general-purpose programming language. I don't use it much myself (I use C, JavaScript, Pari, SQL, Perl, and C# more often) but it's not a bad language.
I'm not sure exactly what you're asking about it.[/QUOTE] I edited a post of mine. |
[QUOTE=science_man_88;239587]I knew the return part was coming lol. yeah I did the eval(Vec(Str())) because I don't know what type they enter so unless I do a check for each type it's easier that way. I used ceil() because my formula wouldn't work without it that way so it's either change the formula or the function I use.[/QUOTE]
Frankly I would use one function for testing for palindromic integers and another for testing strings -- there's no need to have them be the same function. Actually I've never needed or written a program for palindrome testing of strings in Pari, though I have a pretty decent function ispal() for integers. If I'm working with strings I don't like to use Pari. :smile: |
[QUOTE=3.14159;239586]Something that would be nice for Python would be to be able to make a short script to do a primality proof in it. (Special-form primes, preferably, for general primes, use a PRP.)[/QUOTE]
It would be slow. Python is bad with that sort of thing, just like Pari is bad with strings. |
[QUOTE=CRGreathouse;239590]Frankly I would use one function for testing for palindromic integers and another for testing strings -- there's no need to have them be the same function. Actually I've never needed or written a program for palindrome testing of strings in Pari, though I have a pretty decent function ispal() for integers. If I'm working with strings I don't like to use Pari. :smile:[/QUOTE]
what is it with me and the list of complete things lol. |
[QUOTE=CRGreathouse;239591]It would be slow. Python is bad with that sort of thing, just like Pari is bad with strings.[/QUOTE]
Bad at modular reduction? |
[QUOTE=science_man_88;239592]waht is it with me and the list of complete things lol.[/QUOTE]
Heh. :smile: I have a good-sized collection of functions I use often and have modestly efficient code for. Here's an incomplete list of these functions: [code]addhelp(bfile, "bfile(name, v, offset=1): If v is given, creates a b-file with the values of v, using name as the A-number (given as a number or a filename). If v is not given, open the b-file name (again, as a filename or number) and return a vector of its values."); addhelp(bigdiv, "bigdiv(a,b,c,d): Does d divide a^b - c? Same as (a^b-c)%d == 0, but faster for large b. Example: bigdiv(2,p,1,d) checks if d divides the p-th Mersenne number."); addhelp(bigfactor, "bigfactor(a,b,c,lim,{start=2}): Find small prime factors of a^b - c (up to lim). Optional parameter start gives a starting point below which primes are not checked."); addhelp(checkVDW, "checkVDW(vv): Given a partition vv = [p1, p2, ...] with union(p1, p2, ...) = [1, 2, ..., n], finds a lower-bound proof for van der Waerden numbers based on the partition. Returns 0 if vv is not a partition of any initial segment, and k if vv proves that W(#vv, k) > n."); addhelp(contfracback, "contfracback(v, terms): Given a continued fraction v, gives the real number back. If terms is given, use only that many terms."); addhelp(countPowerful, "countPowerful(lim): Number of powerful numbers up to lim. Partial sum of characteristic function of of Sloane's A001694."); addhelp(countSquarefree, "countSquarefree(lim): Counts the number of squarefree numbers up to lim."); addhelp(diffset, "diffset(A, B) is the set of all numbers of the form a-b, a in A, b in B."); addhelp(digits, "digits(n): Number of decimal digits in n. Sloane's A055642."); addhelp(dsum, "dsum(n): Digit sum of n. Sloane's A007953."); addhelp(eps, "Returns machine epsilon for the current precision."); addhelp(Faulhaber, "Faulhaber(e,{a='x}): Returns the polynomial for the sum 1^e + 2^e + ... + x^e, evaluated at a."); addhelp(fibmod, "fibmod(n,m): Returns the nth Fibonacci number mod m. Same as finonacci(n)%m, but faster for large n."); addhelp(fnice, "fnice(n): Returns a string with a 'nice' factorization of n."); addhelp(forbigprime, "forbigprime(X=a,b,seq): the sequence is evaluated, X running over the primes between a and b. EXPERIMENTAL!"); addhelp(forodd, "forodd(X=a,b,seq): the sequence is evaluated, X running over the odds between a and b."); addhelp(forthinprime, "forthinprime(X=a,b,seq): the sequence is evaluated, X running over the primes between a and b, even if b > primelimit. EXPERIMENTAL!"); addhelp(fortwin, "fortwin(X=a,b,seq): the sequence is evaluated, X running over the twin primes between a and b."); addhelp(fusc, "fusc(n): Stern's diatomic series, which has many interpretations. Sloane's A002487."); addhelp(gpf, "The greatest prime factor of a number. Sloane's A006530."); addhelp(hamming, "hamming(n): Hamming weight of n (considered as a binary number). Sloane's A000120."); addhelp(isFibonacci, "isFibonacci(n): Is n a Fibonacci number? Sloane's A010056; characteristic function of Sloane's A000045."); addhelp(isHexagonal, "isHexagonal(n): Is n a hexagonal number? Characteristic function of Sloane's A000384."); addhelp(ispow2, "ispow2(n): Is n a power of two? Characteristic function of Sloane's A000079."); addhelp(isPowerful, "isPowerful(n): Is n powerful (min exponent 2)? Sloane's A112526; characteristic function of Sloane's A001694."); addhelp(isprimepower, "isprimepower(n): Is n a prime power? Sloane's A010055; characteristic function of Sloane's A000961."); addhelp(issemi, "issemi(n): Is n a semiprime? Sloane's A064911; characteristic function of Sloane's A001358."); addhelp(isthree, "isthree(n): Is the number the sum of three squares? Sloane's A071374; characteristic function of Sloane's A000378."); addhelp(isTriangular, "isTriangular(n): Is n a triangular number? Sloane's A010054; characteristic function of Sloane's A000217."); addhelp(istwo, "Is the number a sum of two squares? Characteristic function of Sloane's A001481."); addhelp(largestSquareFactor, "largestSquareFactor(n): Largest square dividing n. Sloane's A008833."); addhelp(lg, "lg(x): Binary logarithm of x."); addhelp(longestProgression1, "longestProgression1(v): Uses a quadratic algorithm of Jeff Erickson, which is worst-case optimal; better algorithms are available when there are long progressions (> lg #v lg lg #v)."); addhelp(longestProgression, "longestProgression(v): Finds the longest arithmetic progression in v. Assumes that v is a vector of integers sorted from smallest to largest. Uses a space-efficient naive algorithm."); addhelp(lpf, "The least prime factor of a number. Sloane's A020639."); addhelp(Mfactor, "Mfactor(p,lim,{start=2}): Returns factors of the Mersenne number 2^p-1 up to lim, starting at start, provided p is a prime = 3 mod 4. Same as bigfactor(2,p,1,lim,start) but faster because it checks only factors of the form 2kp+1 that are +/- 1 mod 8."); addhelp(msb, "msb(n): Most significant bit of n: returns the greatest power of 2 <= the number. Sloane's A053644."); addhelp(nice, "nice(o): Reformats the object o 'nicely' when possible. Currently chokes on multivariable polynomials."); addhelp(normd, "normd(a,b): Amount of the normal distribution between a and b standard deviations. Plus/minus infinity coded as [+1]/[-1]."); addhelp(oddres, "oddres(n): Returns the greatest odd number dividing n."); addhelp(primorial, "Returns the product of each prime less than or equal to n. Sloane's A034386."); addhelp(prp, "prp(n,b=2): Is n a b-probable prime?"); addhelp(rad, "rad(n): Radical of n, the largest squarefree number dividing n. Sloane's A007947."); addhelp(rnormal, "rnormal(): Returns a random normal variable with mean 0 and standard deviation 1 at the current precision."); addhelp(rp, "rp(b): Returns a random b-bit prime."); addhelp(sopfr, "sopfr(n): Sum of prime factors of n (with multiplicity). Sloane's A001414."); addhelp(sopf, "sopf(n): Sum of prime factors of n. Sloane's A008472."); addhelp(sprp, "sprp(n,b=2): Is n a b-strong probable prime?"); addhelp(sumformal, "sumformal(X=start,end,expr): Formal version of sum(X=start,end,expr). Start and end can be expressions instead of numbers."); addhelp(sumset, "sumset(A, B) is the set of all numbers of the form a+b, a in A, b in B."); addhelp(toC, "toC(n): Format n for use with the Pari library (e.g., with gp2c programs)."); addhelp(vecgcd, "Vector gcd: returns the gcd of all elements in the vector."); addhelp(veclcm, "Vector lcm: returns the lcm of all elements in the vector."); addhelp(vecprod, "vecprod(v): Product of the elements of v."); addhelp(vecsum, "vecsum(v): Sum of the elements of v."); addhelp(ways2, "Number of ways that n can be represented as a sum of two squares. Sloane's A000161."); addhelp(ways3, "Number of ways that n can be represented as a sum of three squares. Sloane's A000164."); addhelp(W, "Primary branch of Lambert's W function. Finds an L >= -1 such that L * exp(L) = x, where x >= -1/e.");[/code] |
[QUOTE=3.14159;239593]Bad at modular reduction?[/QUOTE]
Actually it's more about the addition (and, to a lesser degree, multiplciation) performance due to overhead. It's as slow (to first-order) as GP without any of the builtin functions. |
Been thinking of [URL="http://rosettacode.org/wiki/Sierpinski_triangle"]this[/URL] one for a while now. I see the concept hard part is implementing what I know enough lol.
never mind lol I didn't fully get the concept, However I semi get it now. |
1 Attachment(s)
order 6 Sierpinski triangle ?
|
[url]http://rosettacode.org/wiki/Repeat_a_string[/url]
[url]http://rosettacode.org/wiki/Keyboard_Input/Obtain_a_Y_or_N_response[/url] [url]http://rosettacode.org/wiki/Reverse_a_string[/url] [url]http://rosettacode.org/wiki/Read_entire_file[/url] Since when are these not doable in PARI!. Just by looking I know 3 of them and if read(file) does read the full file it covers the last one lol. never mind lol: [B]unenlightening[/B] theres a reason. |
[CODE](b)-> {
my(c=0,d=b,a=0); for(x=1,b,a=random(b); for(y=1,b, if(a<=c||a>=d, a=random(b), break() ) ); print("I guess "a" am I h,l,or e ?"); e=Str(input()); if(e=="h", d=a, if(e=="l", c=a, if(e=="e", break() ) ) ) ); } [/CODE] This should work last i checked but it doesn't. It seems to have trouble with [CODE]if(e=="e",break())[/CODE] I've tried form break() to break(4) no success. Never mind it's because I messed up the loop to check a and I used e both as a value and variable name I guess. I got it working. |
[CODE](b)-> {
my(c=0,d=b,a=0); [COLOR="Red"]for(x=1,b,[/COLOR] [COLOR="DarkOrange"]a=random(b);[/COLOR] [COLOR="Lime"]for(y=1,b, if(a<c||a==c||a==d||a>d, a=random(b), break() ) );[/COLOR] [COLOR="red"]print("I guess "a" am I h,l,or e ?"); g=input(); if(g==h, d=a, if(g==l, c=a, if(g==e, break() ) ) ) )[/COLOR]; }[/CODE] [url]http://rosettacode.org/wiki/Guess_the_number/With_feedback_(player[/url]) The dark orange is a line that can be taken out. |
[url]http://rosettacode.org/wiki/Conditional_structures[/url]
this one is a long list lol; addhelp alias allocatemem apply [COLOR="Lime"]break [/COLOR] default error extern [COLOR="lime"]for fordiv forell forprime forstep forsubgroup forvec[/COLOR] getheap getrand getstack gettime global [COLOR="lime"]if [/COLOR] input install [COLOR="Lime"]kill[/COLOR] local my [COLOR="lime"]next[/COLOR] print print1 printp printp1 printtex quit read readvec return select setrand system [COLOR="lime"]trap[/COLOR] type [COLOR="lime"] until [/COLOR] whatnow [COLOR="lime"]while [/COLOR] write write1 writebin writetex |
[QUOTE][url]http://rosettacode.org/wiki/Repeat_a_string[/url][/QUOTE]
[CODE]repeat(string,x)=for(y=1,x,print1(string))[/CODE] done lol |
[QUOTE=science_man_88;239685][url]http://rosettacode.org/wiki/Repeat_a_string[/url]
[url]http://rosettacode.org/wiki/Keyboard_Input/Obtain_a_Y_or_N_response[/url] [url]http://rosettacode.org/wiki/Reverse_a_string[/url] [url]http://rosettacode.org/wiki/Read_entire_file[/url] Since when are these not doable in PARI!. Just by looking I know 3 of them and if read(file) does read the full file it covers the last one lol. never mind lol: [B]unenlightening[/B] theres a reason.[/QUOTE] I think I was the one who put each of those in PARI/GP/Omit. Read entire file: Not possible* in GP. It can't distinguish between a file containing 1+1 and a file containing 2, for example. Reverse a string: Unenlightening, as you guessed. But [i]you[/i] may very well want to do this one, even though I didn't want to. Get Y/N: Impossible* in GP, since the task requires that only Y or N, not Enter, be pressed. Repeat a string: Unenlightening. Again, feel free to do this anyway. * Not possible without using extern() or system(), as far as I know. |
[QUOTE=CRGreathouse;239704]I think I was the one who put each of those in PARI/GP/Omit.
Read entire file: Not possible* in GP. It can't distinguish between a file containing 1+1 and a file containing 2, for example. Reverse a string: Unenlightening, as you guessed. But [i]you[/i] may very well want to do this one, even though I didn't want to. Get Y/N: Impossible* in GP, since the task requires that only Y or N, not Enter, be pressed. Repeat a string: Unenlightening. Again, feel free to do this anyway. * Not possible without using extern() or system(), as far as I know.[/QUOTE] [CODE]reverse(string)=my(v=Vec(Str(string)),c="");forstep(y=#v,1,-1,c=concat(c,v[y]));c[/CODE] done the reverse. |
[QUOTE=science_man_88;239701][CODE]repeat(string,x)=for(y=1,x,print1(string))[/CODE]
done lol[/QUOTE] I think you need to return the result as a string rather than print multiple copies. |
[QUOTE=science_man_88;239706][CODE]reverse(string)=my(v=Vec(Str(string)),c="");forstep(y=#v,1,-1,c=concat(c,v[y]));c[/CODE]
done the reverse.[/QUOTE] Great! Add it. You may also want to register on RC so that your contributions show up under your name (or rather your chosen pseudonym) instead of under your IP address. |
[QUOTE=CRGreathouse;239709]Great! Add it.
You may also want to register on RC so that your contributions show up under your name (or rather your chosen pseudonym) instead of under your IP address.[/QUOTE] maybe I'm having one difficulty for the file read: [CODE]read_file_completely(file)= a=Vec(Str(read(file)));for(x=1,#a,print(a[x]))[/CODE] if I don't go " before a path the : makes it end , if I do use " before and after it says variable name expected. when i then use, p="E:\\output.txt" it gives me *** error opening input file: E:\output.txt if we can get around that it's home free. doh i know why i deleted that file lol. [code](14:35) gp > read_file_completely(p="E:\\modulo.txt") 369369369369369369369369369369[/code] now we are getting somewhere as that is a line in the file, however not the first. |
[QUOTE=science_man_88;239700][url]http://rosettacode.org/wiki/Conditional_structures[/url]
this one is a long list lol; addhelp alias allocatemem apply [COLOR="Lime"]break [/COLOR] default error extern [COLOR="lime"]for fordiv forell forprime forstep forsubgroup forvec[/COLOR] getheap getrand getstack gettime global [COLOR="lime"]if [/COLOR] input install [COLOR="Lime"]kill[/COLOR] local my [COLOR="lime"]next[/COLOR] print print1 printp printp1 printtex quit read readvec return select setrand system [COLOR="lime"]trap[/COLOR] type [COLOR="lime"] until [/COLOR] whatnow [COLOR="lime"]while [/COLOR] write write1 writebin writetex[/QUOTE] Hmm. I wouldn't consider break a conditional structure, although it can be used with them. I don't think the page counts loops, although you're certainly right that they are actually conditional. kill and next aren't conditional in similar fashion to break. That leaves if and maybe trap. You could also add && and || (or their short forms & and |) because they short-circuit: 1&print("this happens"); 0&print("this doesn't"); |
[QUOTE=science_man_88;239711]when i then use, p="E:\\output.txt" it gives me *** error opening input file: E:\output.txt if we can get around that it's home free. doh i know why i deleted that file lol.[/QUOTE]
You might be able to make that work by reversing \ and /, I'm not sure. But I think this task is not solvable because GP evaluates the contents of the file so two files that are different but evaluate to the same thing can't be distinguished. |
[QUOTE=CRGreathouse;239715]You might be able to make that work by reversing \ and /, I'm not sure.
But I think this task is not solvable because GP evaluates the contents of the file so two files that are different but evaluate to the same thing can't be distinguished.[/QUOTE] I know what messes it up control characters like enter. If I straighten the file to one line it read it all if not it only evaluated the last line. though 0 seemed to mess it up as well if all numerical.if we can get past that, and I have an idea how,but I don't know how slow it would be. |
[QUOTE=science_man_88;239722]I know what messes it up control characters like enter. If I straighten the file to one line it read it all if not it only evaluated the last line.
though 0 seemed to mess it up as well if all numerical.if we can get past that, and I have an idea how,but I don't know how slow it would be.[/QUOTE] I'm not talking about escaping the backslashes "c:\\documents and settings\\foo\\bar.gp" but about replacing them with slashes, which as it happens do not need to be escaped: "c:/documents and settings/foo/bar.gp" This is, as I understand, an artifact of the system (cygwin? mingw?) that underlies the Windows version of GP. |
[QUOTE=CRGreathouse;239730]I'm not talking about escaping the backslashes
"c:\\documents and settings\\foo\\bar.gp" but about replacing them with slashes, which as it happens do not need to be escaped: "c:/documents and settings/foo/bar.gp" This is, as I understand, an artifact of the system (cygwin? mingw?) that underlies the Windows version of GP.[/QUOTE] I'm not talking in the file name I'm talking in the file if we can remove things like enters and 0's we could do it I think. The enters can be done with deleting the last line and repeated reading it into a Vec. For the 0's i was thinking of appending something on the front of each line then getting rid of it later but that's not so helpful. |
[QUOTE=science_man_88;239731]I'm not talking in the file name I'm talking in the file if we can remove things like enters and 0's we could do it I think. The enters can be done with deleting the last line and repeated reading it into a Vec. For the 0's i was thinking of appending something on the front of each line then getting rid of it later but that's not so helpful.[/QUOTE]
So all you have to do is read in the file, change the... wait... :smile: |
[QUOTE=CRGreathouse;239733]So all you have to do is read in the file, change the... wait... :smile:[/QUOTE]
[B]entire contents[/B] however if i load individual lines in and replace the enters and 0's when I'm done I did get the entire contents lol. |
[QUOTE=science_man_88;239735][B]entire contents[/B]
however if i load individual lines in and replace the enters and 0's when I'm done I did get the entire contents lol.[/QUOTE] 1. Not good enough; if you have to do something this means GP isn't doing it on its own. 2. You wouldn't get the contents of the file but the contents of the edited file; you'd need to remember what you changed and change it back. This would probably be very hard to do. |
[QUOTE=CRGreathouse;239736]1. Not good enough; if you have to do something this means GP isn't doing it on its own.
2. You wouldn't get the contents of the file but the contents of the edited file; you'd need to remember what you changed and change it back. This would probably be very hard to do.[/QUOTE] the enters are easy the 0's are the hard part. [CODE](16:28) gp > read_file_completely(file)= b=[];a=eval(Vec(Str(read(file))));b=concat(a,b); (16:28) gp > read_file_completely("e:\\modulo.txt") %279 = [3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9][/CODE] also I can get the file up back in full i believe. I'd do it in the script lol. |
on another script:
[url]http://rosettacode.org/wiki/Day_of_the_week[/url] is in the can't be done etc. but: [url]http://rosettacode.org/wiki/Five_weekends[/url] in the to do list would use it. |
control characters
[U]what I've found to work for me:
[/U] print("\t") -> tab print("\n") -> newline looking up things about javascript control characters gave me these. never mind only; [url]http://rosettacode.org/wiki/Special_characters#PARI.2FGP[/url] which list 4 lol |
[QUOTE=science_man_88;239738]the enters are easy the 0's are the hard part.
[CODE](16:28) gp > read_file_completely(file)= b=[];a=eval(Vec(Str(read(file))));b=concat(a,b); (16:28) gp > read_file_completely("e:\\modulo.txt") %279 = [3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3, 6, 9][/CODE] also I can get the file up back in full i believe. I'd do it in the script lol.[/QUOTE] Try this in a file:[INDENT]1+1;v=n->n^2;[/INDENT] |
Charles; Can you make scripts in Sage? I'm too lazy to go through the whole process of trying to install and run it on here.
|
[QUOTE=CRGreathouse;239757]Try this in a file:[INDENT]1+1;v=n->n^2;[/INDENT][/QUOTE]
is there a way to fix pari back to installed defaults ? I played too much with things i hate the view lol. it acted as code or gave me back an error lol but without it it didn't |
| All times are UTC. The time now is 23:20. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.