mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Software (https://www.mersenneforum.org/forumdisplay.php?f=10)
-   -   I'll send you an Amazon.com book for making this program. (https://www.mersenneforum.org/showthread.php?t=7423)

jasong 2007-03-14 23:51

I'll send you an Amazon.com book for making this program.
 
I have no programming skills and I'm getting frustrated with all the typing/copying/pasting I'm having to do in the octoproth search.

I'll give an Amazon book(paperback) to whoever can accomplish the following(first come first served).

I'm guessing it'll be a command-line batch file, I don't know. Basically, it takes the following parameters(an instruction file to go along with the program would be great). The n-value, the range of k in trillion(it would automatically add the 12 zeroes when it made the file), how many k per line, in trillion. then the filename it would go to/be appended to. Alternately, it would be nice if n could be entered as a range, and grouped with commas(300-305,307 would do all n-values from 300 to 307, except 306)Basically it would be something like:

[code]command.bat 300 0 1000 50 >> test.bat[/code]
result:
[code]octo_6_0 300 0 50000000000000
octo_6_0 300 50000000000000 100000000000000
octo_6_0 300 100000000000000 150000000000000
octo_6_0 300 150000000000000 200000000000000
octo_6_0 300 200000000000000 250000000000000
octo_6_0 300 250000000000000 300000000000000
octo_6_0 300 300000000000000 350000000000000
octo_6_0 300 350000000000000 400000000000000
octo_6_0 300 400000000000000 450000000000000
octo_6_0 300 450000000000000 500000000000000
octo_6_0 300 500000000000000 550000000000000
octo_6_0 300 550000000000000 600000000000000
octo_6_0 300 600000000000000 650000000000000
octo_6_0 300 650000000000000 700000000000000
octo_6_0 300 700000000000000 750000000000000
octo_6_0 300 750000000000000 800000000000000
octo_6_0 300 800000000000000 850000000000000
octo_6_0 300 850000000000000 900000000000000
octo_6_0 300 900000000000000 950000000000000
octo_6_0 300 950000000000000 1000000000000000[code]
I do intend to take a C programming course during the summer, but I have no skills at the moment.

potonono 2007-03-15 03:04

1 Attachment(s)
For quick and dirty programs, I use [URL="http://www.cs.arizona.edu/icon/"]Icon[/URL] since it doesn't take to much to test, and because they have a free compiler. Attached is a zip file containing the source below, and the command line program compiled for use in Windows.

I didn't include an option to range the n_value, but I'm lazy like that sometimes. :)


[CODE]procedure main(args)

if ( (args[1] == "\\?") | (args[1] == "/?") | (args[1] == "help") ) then {
write("jasong_cmd n_value k_begin k_end k_per_line output_file")
write("")
write("n_value Specifies the value of n")
write("k_begin Specifies the beginning range of k in trillions")
write("k_end Specifies the ending range of k in trillions")
write("k_per_line Specifies the increment of k in trillions")
write("output_file Specifies the output file to create")
write("")
write("")
write("Example: jasong_cmd 300 0 1000 50 test.bat")
write("")
}
else{
#assign arguments to recognizable variable names
n_value := args[1]
k_begin := args[2]
k_end := args[3]
k_per_line := args[4]
output_file := args[5]

#open output file
if not (output_file === &null) then { output := open(output_file, "a") }

#if not starting at zero, start first value in trillions
k_current := k_begin
writes(output,"octo_6_0 ",n_value," ",k_begin)
if not ( k_begin < 1 ) then { writes(output,"000000000000") }
write(output," ",k_begin + k_per_line,"000000000000")
k_current := k_current + k_per_line

#write remaining values
while ( k_current < k_end ) do {
write(output,"octo_6_0 ",n_value," ",k_current,"000000000000 ",k_current + k_per_line,"000000000000")
k_current := k_current + k_per_line
}

#close output file
if not (output_file === &null) then { close(output) }

}
end[/CODE]

jasong 2007-03-15 10:01

[QUOTE=potonono;100848]For quick and dirty programs, I use [URL="http://www.cs.arizona.edu/icon/"]Icon[/URL] since it doesn't take to much to test, and because they have a free compiler. Attached is a zip file containing the source below, and the command line program compiled for use in Windows.

I didn't include an option to range the n_value, but I'm lazy like that sometimes. :)[/QUOTE]
Since you didn't mention an Amazon book, do you have a favorite charity that would accept $5 Paypal?

potonono 2007-03-16 01:43

Maybe put it towards the [URL="http://www.mersenneforum.org/showthread.php?t=5860"]Gimps Prize[/URL]? :smile:

Eivind 2007-03-16 11:24

Hi Jasong

This python ([url]www.python.org[/url]) program should do the trick.

[CODE]import sys
import os

if len(sys.argv) != 7:
print "The program takes 6 argv; start number of n, stop number of n, start value of k, stop value of k, incriments, fil name. If file exist data is appended otherwise the file is created."
sys.exit()

if os.path.exists(sys.path[0] + "\\" + sys.argv[6]):
output = file(sys.path[0] + "\\" + sys.argv[6], "a")
else:
output = file(sys.path[0] + "\\" + sys.argv[6], "w")

for h in range(int(sys.argv[1]), int(sys.argv[2])+1):
for i in range(int(sys.argv[3]), int(sys.argv[4]), int(sys.argv[5])):
output.write("octo_6_0 %d %d %d \n" % (h, i*int(1E12), i*int(1E12)+int(sys.argv[5])*int(1E12)))

output.close()
[/CODE]

Just save the code as "jasong.py"

It is commandline driven: jasong.py 300 300 0 1000 50 test.txt

It is quite hard to do the grouping trick, so the program takes a start value for n and an end value for n. Incriment for n is 1.

If the file exist data is appended, otherwise a new file is created.

So your 300-305,307 values for n goes like this:

jasong.py 300 305 0 1000 50 test.txt
jasong.py 307 307 0 1000 50 test.txt

If (k high - k low)/incriment is not a hole number the last number in the last line will exide k high.

I can“t test the code in unix envirement, there might be some problems with the generation of the file neme due to changes in \ and /. Let me know if you get any problems.

-Eivind

Ps. No book is needed - save it for better hardware :devil:

paulunderwood 2007-03-16 19:45

[CODE]if os.path.exists(sys.path[0] + "\\" + sys.argv[6]):
output = file(sys.path[0] + "\\" + sys.argv[6], "a")
else:
output = file(sys.path[0] + "\\" + sys.argv[6], "w")[/CODE]

Can the above be replaced by:

[CODE]
output = file(sys.argv[6], "a")
[/CODE]

?

Eivind 2007-03-21 09:25

Hi Poul

Your right, that code works corretly, so no need to import the os :grin:

This boils the code down to:

[CODE]
import sys

if len(sys.argv) != 7:
print "The program takes 6 argv; start number of n, stop number of n, start value of k, stop value of k, incriments, fil name. If file exist data is appended otherwise the file is created."
sys.exit()

output = file(sys.argv[6], "a")

for h in range(int(sys.argv[1]), int(sys.argv[2])+1):
for i in range(int(sys.argv[3]), int(sys.argv[4]), int(sys.argv[5])):
output.write("octo_6_0 %d %d %d \n" % (h, i*int(1E12), i*int(1E12)+int(sys.argv[5])*int(1E12)))

output.close()
[/CODE]

-Eivind


All times are UTC. The time now is 22:56.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.