Program to save number list in txt file ( 000000 to 606060 )

  • Detlev
  • Graduate
  • Graduate
  • User avatar
  • Joined: 27 Sep 2004
  • Posts: 132
  • Loc: In front o' Computer.
  • Status: Offline

Post December 4th, 2004, 4:48 pm

Is anyone up to making, for free, a program that would list all possible numbers from 000000 to 606060 and then save it into a .txt file. If so that would be great if not, w/e. Thanks in advanced to everyone. O! and if you know of any place on the net i could get one just do that instead. Thanks.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 4th, 2004, 4:48 pm

  • aeon
  • Graduate
  • Graduate
  • User avatar
  • Joined: 31 Oct 2004
  • Posts: 184
  • Loc: Ireland
  • Status: Offline

Post December 4th, 2004, 6:23 pm

you didn't specify a language so... here it in in perl

$numbers = "numbers.txt";
open(INFO, "+>$numbers") ;

for($i = 0; $i < 606061; $i++) {
   print INFO "$i\n";
}

close(INFO);


go to http://www.perl.org and download the interpreter for your platform, you may also want to download something to convert it to an executable, i can't think of one off hand but googling should turn up something
  • Maedhros
  • Proficient
  • Proficient
  • User avatar
  • Joined: 31 Oct 2004
  • Posts: 325
  • Loc: Durham, England
  • Status: Offline

Post December 5th, 2004, 8:27 am

And in PHP:
[php]$filename = "numbers.txt";
$file = fopen($filename, "w+");

for ($i = 0; $i <= 606060; $i++) {
if (!fwrite($file, "$i\n")) {
die ("Could not write to file $filename");
}
}

fclose($file);[/php]

Or in BASH:
FILENAME="numbers.txt"
touch "numbers.txt"

for i in $(seq 0 606060); do
    echo "$i" >> $FILENAME
done


Note: The BASH script took 13.6s to run, the PHP script took 2s, and the Perl script took a hair under half a second. They all produce an identical 4Mb file.
Gentoo Linux: "All of a sudden, Larry the Cow was in control. And he liked it."
  • aeon
  • Graduate
  • Graduate
  • User avatar
  • Joined: 31 Oct 2004
  • Posts: 184
  • Loc: Ireland
  • Status: Offline

Post December 5th, 2004, 11:14 am

and here it is in c++

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
   ofstream out;
   out.open ("numbers.txt");
   
   for(int i = 0; i < 606061; i++)
      out << i << endl;
      
   out.close();
}


takes about 10 seconds to run. There's also the compile time and the fact that it took longer to code... I love Perl

edit: python

out = open('numbers.txt', 'w')
a = 10

i = 0

for x in range (606061):
        string = str(i)
        fout.write(string)
        fout.write("\n")
        i+=1


this ones a bit quicker than c++, but it took the longest to code (since i had to learn some python first)
  • Mas Sehguh
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: 07 Aug 2004
  • Posts: 1854
  • Status: Offline

Post December 5th, 2004, 3:28 pm

Here it is in Reverse Polish Lisp:
« "" 0 606060 FOR Z Z + "
" + NEXT 'output.txt' STO »


Of course, maybe he wants a file that looks like this:
000000
000001
000002
000003
...


So...
« "" 1000000 1606060 FOR Z Z →STR TAIL + "
" + NEXT 'output.txt' STO »
  • aeon
  • Graduate
  • Graduate
  • User avatar
  • Joined: 31 Oct 2004
  • Posts: 184
  • Loc: Ireland
  • Status: Offline

Post December 5th, 2004, 5:01 pm

i made a minor change in my c++ for the leading 0's

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
   ofstream out;
   out.open ("numbers.txt");

   for(int i = 0; i < 606061; i++)
      out << setw(6) << setfill('0') << i << endl;

   out.close();
}


EDIT: perl fix

$numbers = "numbers.txt";
open(INFO, "+>$numbers") ;

$num = '000000';

for($i = 0; $i < 606061; $i++) {
        print INFO "$num\n"; $num++;
}

close(INFO);
  • Maedhros
  • Proficient
  • Proficient
  • User avatar
  • Joined: 31 Oct 2004
  • Posts: 325
  • Loc: Durham, England
  • Status: Offline

Post December 5th, 2004, 5:27 pm

For leading zeroes...

[php]$filename = "numbers.txt";
$file = fopen($filename, "w+");

for ($i = 0; $i <= 606060; $i++) {
$length = strlen($i);
$padding = str_repeat("0", (6 - $length));

fwrite($file, $padding.$i."\n");
}

fclose($file);[/php]

And for bash, replace $(seq 0 606060) with $(seq -w 0 606060). :)

Edit: I'm an idiot... replace all the BASH code with this, and it will run about 5 times faster...
seq -w 0 606060 > numbers.txt
Gentoo Linux: "All of a sudden, Larry the Cow was in control. And he liked it."
  • SpooF
  • Ice Cream
  • Bronze Member
  • User avatar
  • Joined: 22 May 2004
  • Posts: 2616
  • Loc: Richland, WA
  • Status: Online

Post December 5th, 2004, 5:40 pm

may i ask why might you need something that lists every number from 0 to 606060 ?

p.s VBscript anyone? i was looken at javascript but there is no i/o for it. java?
  • lucassix
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: 13 Sep 2004
  • Posts: 2317
  • Loc: Living in a VAN DOWN BY THE RIVER!
  • Status: Offline

Post December 5th, 2004, 6:13 pm

How about.... BASIC!

DIM TextFile$
PRINT "Enter a path and file name for the text file."
INPUT "(Stick to 8.3 paths, this is BASIC you know):", TextFile$
PRINT " "
PRINT "Writing 000000 to 606060..."
OPEN TextFile$ FOR APPEND AS #1
n = 0
DO
PRINT #1, n
n = n + 1
LOOP UNTIL n = 606061
CLOSE #1
PRINT "Done!"
SHELL "PAUSE"


And here is it compiled for you: http://home.satx.rr.com/airforcedave/606060.EXE (40KB)

//EDIT: BASIC doesn't like leading zeros, so still working on that...
  • Detlev
  • Graduate
  • Graduate
  • User avatar
  • Joined: 27 Sep 2004
  • Posts: 132
  • Loc: In front o' Computer.
  • Status: Offline

Post December 5th, 2004, 8:26 pm

wowsers. thanks for the many replies.
  • Detlev
  • Graduate
  • Graduate
  • User avatar
  • Joined: 27 Sep 2004
  • Posts: 132
  • Loc: In front o' Computer.
  • Status: Offline

Post December 5th, 2004, 8:44 pm

I tried the basic one, thank you for doing that for me, but I don;t think I explained this correctly. I wanted the numbers:
000001
000002
000003....

Basically; and the reason is because I was wondering what all the possible numbers on a combination lock was. I wasn't sure of the highest possible number but I knew it was not greater than 60. O! and I can see you asking why I would want to know that; the answer is really, im entertained by stupid things such as that and, well im an idiot that is easily amused.
  • Detlev
  • Graduate
  • Graduate
  • User avatar
  • Joined: 27 Sep 2004
  • Posts: 132
  • Loc: In front o' Computer.
  • Status: Offline

Post December 5th, 2004, 10:47 pm

I think you need something like an algorithem, I have no clue, that's why I came here.
  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: 21 May 2004
  • Posts: 3022
  • Loc: South Africa
  • Status: Offline

Post December 6th, 2004, 12:13 am

Okay my advice. Go to google and find out what an algorithm is.

Just a quicky though, all the above are basic algorithms.

Quote:
Reverse Polish Lisp

Only you Sam ;)

Interesting read
http://www.engr.uvic.ca/~aschoorl/faq/48faq-8.html
  • aeon
  • Graduate
  • Graduate
  • User avatar
  • Joined: 31 Oct 2004
  • Posts: 184
  • Loc: Ireland
  • Status: Offline

Post December 6th, 2004, 7:03 am

Quote:
I tried the basic one, thank you for doing that for me, but I don;t think I explained this correctly. I wanted the numbers:
000001
000002
000003....


both the perl one and the c++ one do that..

I've uploaded a c++ executable here
  • Detlev
  • Graduate
  • Graduate
  • User avatar
  • Joined: 27 Sep 2004
  • Posts: 132
  • Loc: In front o' Computer.
  • Status: Offline

Post December 6th, 2004, 2:41 pm

super cool you guys are all awsome, i must study how this works.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 6th, 2004, 2:41 pm

Post Information

  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2008. Driven by phpBB © 2001-2008 phpBB Group.

 
 
 

Need a pre-made web design for your website?

Check out our templates here: Ozzu Templates

Perfect Money : Swiss approach to work with e-finance