![]() |
[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. |
| All times are UTC. The time now is 23:09. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.