mersenneforum.org PARI/GP tips and tricks
 Register FAQ Search Today's Posts Mark Forums Read

2022-12-23, 00:31   #45
Dr Sardonicus

Feb 2017
Nowhere

23×19×41 Posts

Quote:
 Originally Posted by charybdis divisors() can take a factorization matrix as input.
D'oh!

I should have just tried that! I should have realized it was very likely to work.

[tries an example, and it does indeed work]

Thank you!

 2022-12-23, 00:55 #46 R. Gerbicz     "Robert Gerbicz" Oct 2005 Hungary 5×17×19 Posts Once you factored n, you could add the primefactors, so then a new numdiv/divisors or any such functions when you know factor() would be called will be much faster. Code: ? ?addprimes addprimes({x=[]}): add primes in the vector x to the prime table to be used in trial division. x may also be a single integer. Composite "primes" are NOT allowed. But if you would add too "many" factors, then it could actually slow down these calls, because the code goes through the added primes list (until n is not factorised). Really helpful, used it in real codes.
 2023-01-12, 15:13 #47 paulunderwood     Sep 2002 Database er0rr 449610 Posts How do I increase threadsizemax before running gp under Linux? I.e. what do I need to put in \$HOME/.gprc?
 2023-01-25, 07:50 #48 bur     Aug 2020 79*6581e-4;3*2539e-3 659 Posts To have a progress bar, it would be useful to output a string to the same line, overwriting the previous output. Is that possible? Maybe by using "delete" characters as print() arguments?
2023-01-25, 11:33   #49
Neptune

"Martin Hopf"
Jul 2022
Germany

2·3·7 Posts

Quote:
 Originally Posted by bur To have a progress bar, it would be useful to output a string to the same line, overwriting the previous output. Is that possible? Maybe by using "delete" characters as print() arguments?
This should work with printf():
Code:
printf(" ... %c", ... , 13)
with decimal '13' means the ASCII code for carriage return.

For example counting primes up to 10^9 and get progress information in a fixed line would look like this:
Code:
c=0;s=1e9;forprime(p=2,s,c++;if(c%10^5==0,printf(" %3.1f%%  %c",p/s*100,13)));c
Of course frequently calling printf() will slow down the loop, so in this example it is done only after every 100,000-th prime.

Last fiddled with by Neptune on 2023-01-25 at 12:13 Reason: extension

 2023-01-25, 12:45 #50 Neptune     "Martin Hopf" Jul 2022 Germany 528 Posts A carriage return is also possible with: Code: print1(strchr(13))
 2023-01-25, 15:34 #51 bur     Aug 2020 79*6581e-4;3*2539e-3 659 Posts Thanks, that seems to be what I was looking for!
 2023-01-26, 04:44 #52 a1call     "Rashid Naimi" Oct 2015 Remote to Here/There 23·293 Posts Very nice Neptune. Thank you. I too have been looking for a carriage return without the linefeed to no avail. I have vague memory of cls in the old DOS having a similar functional use. I checked it just now and it works too: Code: \\ To Clear the Screen system("cls") \\ Note: * Not sure if it would work on a Linux system. Adding your code to my library. Thanks again. Last fiddled with by a1call on 2023-01-26 at 04:50
2023-01-26, 08:15   #53
paulunderwood

Sep 2002
Database er0rr

119016 Posts

Quote:
 Originally Posted by a1call Very nice Neptune. Thank you. I too have been looking for a carriage return without the linefeed to no avail. I have vague memory of cls in the old DOS having a similar functional use. I checked it just now and it works too: Code: \\ To Clear the Screen system("cls") \\ Note: * Not sure if it would work on a Linux system.
On Linux it is the clear command.

Cross platform: print("\e[H\e[2J")

Last fiddled with by paulunderwood on 2023-01-26 at 08:20

 2023-01-26, 08:52 #54 a1call     "Rashid Naimi" Oct 2015 Remote to Here/There 234410 Posts Noted and filed to my library. Thank you.
 2023-01-26, 13:06 #55 EdH     "Ed Hall" Dec 2009 Adirondack Mtns 149016 Posts I've been using printf "Text, text, text. \r" in my bash scripts in linux. Less for me to remember, although from my Windows days I can still remember cr = 13.

 Similar Threads Thread Thread Starter Forum Replies Last Post paul0 Programming 2 2015-11-17 13:04 davar55 Hobbies 11 2013-05-27 14:28 wblipp Factoring 4 2011-04-15 16:22 Bob Stein Information & Answers 1 2008-04-11 17:52 Unreg Hardware 6 2004-09-18 18:19

All times are UTC. The time now is 14:06.

Wed Feb 8 14:06:51 UTC 2023 up 174 days, 11:35, 1 user, load averages: 0.72, 0.85, 0.86