mersenneforum.org  

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

Reply
 
Thread Tools
Old 2010-12-04, 12:54   #1992
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by kar_bon View Post
Thanks for the notes.
I've not yet read much about the special cases of PARI, so for example the 'return' I did is more from others languages they do this.
The "foo>>2" shift (like a division by a power of 2) is like in C but I don't want to use it to be more closer to the algorithm of the calculation of the Julian Date.
The round-part was not in my mind... I have to develop more in PARI first to know all basic parts and how to use.

Here's the code with your hints and suggestions:
Code:
JulianDate(YYYY,MM,DD)={
  my(a=0, b=0, Y=YYYY, M=MM);
  if(MM<3, Y--; M+=12);
  a=Y\100;
  b=2-a+a\4;
  if(YYYY<=1582 && MM<=10 && DD<=15, b=0);
  floor(365.25*(Y+4716)) + floor(30.6001*(M+1)) + DD + b - 1524.5
};

DayOfWeek(JD)={
  my(DayName=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]);
  DayName[round(JD)%7+1]
};

Day_of_the_week={
  for(year=2008,2121,
       if(DayOfWeek(JulianDate(year,12,25))=="Sunday",print(year)));
}
Please feel free to insert this code in the related page and perhaps the other two tasks.
the date of the week one I said was important as it looks as though
http://rosettacode.org/wiki/Five_weekends may need it to check.

on another topic one thing I liked to do in javascript was what I called rainbow background ( pretty much settimeouts() and color changes going through the rainbow for the background color of the page (you could do this with frames of a movie I think for background image), for the first one is there anything like this in PARI best I can think of is like a rate counter but with a default color change as the code), with Javscript you could turn the effect all the way to 1 ms per color ( bound to give someone epileptic shock))

Last fiddled with by science_man_88 on 2010-12-04 at 13:02
science_man_88 is offline   Reply With Quote
Old 2010-12-04, 13:53   #1993
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

http://rosettacode.org/wiki/Sudoku

"partially filled-in normal 9x9 Sudoku grid"

But it looks as though you make one to start as it doesn't give one ! random(9) anyone lol just have to check i'th row the row the number is in and a 3 by 3 box that is the hard part. I wanted to make matrix(3*matrix(3,3),3*matrix(3,3)) but it doesn't work lol.
science_man_88 is offline   Reply With Quote
Old 2010-12-04, 20:25   #1994
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

203008 Posts
Default

Code:
{for(n=1,100,
  print(if(n%3,
    if(n%5,
      n
    ,
      "Buzz"
    )
  ,
    if(n%5,
      "Fizz"
    ,
      "FizzBuzz"
    )
  ))
)}
It appears to work but I'm stumped , looks to me like this should print n if n%15,buzz if %3, fizz if %5, ans fizzbuzz for anything else. I must be forgetting syntax, never mind i understand lol because %x is the same as writing y%x!=0 ?

Last fiddled with by science_man_88 on 2010-12-04 at 20:27
science_man_88 is offline   Reply With Quote
Old 2010-12-04, 23:09   #1995
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Now that I think about it, you could even do
Code:
DayOfWeek(JD)={
  ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"][round(JD)%7+1]
};
if desired,
CRGreathouse is offline   Reply With Quote
Old 2010-12-04, 23:13   #1996
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Code:
isnumerical(string)=if(type(string)==t_INT || type(string)==t_REAL || type(string)==t_FRAC || type(string)==t_COMPLEX,return(1),return(0))
is as much as I can figure out for:

http://rosettacode.org/wiki/Determin...ing_is_numeric
science_man_88 is offline   Reply With Quote
Old 2010-12-05, 01:27   #1997
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
Code:
isnumerical(string)=if(type(string)==t_INT || type(string)==t_REAL || type(string)==t_FRAC || type(string)==t_COMPLEX,return(1),return(0))
You need quotes. Also, no need for if(a==b || c == d, 1, 0), just do a==b || c==d:
Code:
isnumerical(string)=my(t=type(string));t=="t_INT" || t=="t_REAL" || t=="t_FRAC" || t=="t_COMPLEX";
Quote:
Originally Posted by science_man_88 View Post
is as much as I can figure out for:

http://rosettacode.org/wiki/Determin...ing_is_numeric
Well, your code doesn't quite answer the question. It's saying: given a string (so type(string) == "t_STR"), does it represent a number?

For example, isNumericString("123") should return 1, while isNumericString("1+1") and isNumericString("foo") should return 0.
CRGreathouse is offline   Reply With Quote
Old 2010-12-05, 01:30   #1998
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

203008 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
You need quotes. Also, no need for if(a==b || c == d, 1, 0), just do a==b || c==d:
Code:
isnumerical(string)=my(t=type(string));t=="t_INT" || t=="t_REAL" || t=="t_FRAC" || t=="t_COMPLEX";


Well, your code doesn't quite answer the question. It's saying: given a string (so type(string) == "t_STR"), does it represent a number?

For example, isNumericString("123") should return 1, while isNumericString("1+1") and isNumericString("foo") should return 0.
I have another method but it won't work for anything but integers, so it's also useless.

I've tried every combo of Vec string and eval I can think of to try and take it out of string form but I can't make it work.

Last fiddled with by science_man_88 on 2010-12-05 at 01:32
science_man_88 is offline   Reply With Quote
Old 2010-12-05, 01:37   #1999
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I've tried every combo of Vec string and eval I can think of to try and take it out of string form but I can't make it work.
eval is the wrong tool, since type(eval("1+1")) == "t_INT". You need to go character-by-character and see if all characters are digits (and that there's at least one digit). This will check if the string represents an integer. Oh, you also need to allow either a single - or a single + as the first character.

You then also need to check for real numbers, which may be of the form
(integer).
(integer).(+integer)
.(+integer)
(integer)e(integer)
(integer).e(integer)
(integer).(+integer)e(integer)
.(+integer)e(integer)

Oh yes, and the two forms starting with . can also have a + or - prepended. And the e can be capital.

You could also check for rationals and complex numbers, but you could probably submit without.
CRGreathouse is offline   Reply With Quote
Old 2010-12-05, 01:41   #2000
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
eval is the wrong tool, since type(eval("1+1")) == "t_INT". You need to go character-by-character and see if all characters are digits (and that there's at least one digit). This will check if the string represents an integer. Oh, you also need to allow either a single - or a single + as the first character.

You then also need to check for real numbers, which may be of the form
(integer).
(integer).(+integer)
.(+integer)
(integer)e(integer)
(integer).e(integer)
(integer).(+integer)e(integer)
.(+integer)e(integer)

Oh yes, and the two forms starting with . can also have a + or - prepended. And the e can be capital.

You could also check for rationals and complex numbers, but you could probably submit without.
what if they give 2^p-1 ? is that counted as complex with eval ?
science_man_88 is offline   Reply With Quote
Old 2010-12-05, 01:44   #2001
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
what if they give 2^p-1 ? is that counted as complex with eval ?
If you are passed the string "2^p-1" then the answer should be 0.
CRGreathouse is offline   Reply With Quote
Old 2010-12-05, 01:46   #2002
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
If you are passed the string "2^p-1" then the answer should be 0.
This sounds too hard, too many things to look for.
science_man_88 is offline   Reply With Quote
Reply

Thread Tools


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:51.


Fri Aug 6 22:51:15 UTC 2021 up 14 days, 17:20, 1 user, load averages: 3.65, 4.04, 3.89

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.