FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » How long will it take to calculate the Alphabet?

   
Author Topic: How long will it take to calculate the Alphabet?
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
How long would it take to calculate every possible permutation of the alphabet? I have the program running now.
IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
That depends entirely on how efficient your program is, to be sure. But consider that the actual number of permutations is 29!, or 8.8x10^30. I must say I hope you're not writing that to a logfile.

Hang on, the handicapped English alphabet, being for special people, only has 26 letters, so the number is actually only 4x10^26. I stand by my remarks otherwise.

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Dagonee
Member
Member # 5818

 - posted      Profile for Dagonee           Edit/Delete Post 
Assuming each permutation is 26 places long, there are 4.03 X 10^26 possible permutations.

So a good long while. If you have a 2GHz processor and each permutation only takes one cycle to calculate, it would take 6,394,144,171 years.

Edit: that would be a little shorter than half the time the universe has existed.

Posts: 26071 | Registered: Oct 2003  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
You did mean permutations using all 26 elements, right? If you're also counting the ones with 25 elements, 24 elements, and so on, then of course the number goes up a bit. [Smile]
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Dagonee
Member
Member # 5818

 - posted      Profile for Dagonee           Edit/Delete Post 
BTW, if you did this recursively, I see a stack overflow in your future.

If you didn't do this recursively, then either a memory allocation failure or stack overflow is in your future.

Posts: 26071 | Registered: Oct 2003  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
quote:
that would be a little shorter than half the time the universe has existed.
Or roughly one million times as long, depending on whose numbers you believe. [Big Grin]
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Dagonee
Member
Member # 5818

 - posted      Profile for Dagonee           Edit/Delete Post 
Either way, Windows Vista is going to be unsupported before he finishes.
Posts: 26071 | Registered: Oct 2003  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Well, I dunno. After all, your calculation was for a 2GHz single processor. He might be using a quad-core 4GHz processor, speeding up the calculation by a factor of eight!

Or you could write a virus to take over large parts of the Internet for you, making a massively-parallel computer - perfect for this kind of very subdivisible problem - that could do it in a mere million years or so.

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
David Bowles
Member
Member # 1021

 - posted      Profile for David Bowles   Email David Bowles         Edit/Delete Post 
And perhaps take on an irritating personality that can also jump ships across vast distances!
Posts: 5663 | Registered: Jun 2000  |  IP: Logged | Report this post to a Moderator
Mucus
Member
Member # 9735

 - posted      Profile for Mucus           Edit/Delete Post 
Writing a program on a multi-core processor isn't going to automatically make it concurrent, and it is my educated guess that Blayne probably did not code a concurrent program to do the calculation.
Posts: 7593 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
Dagonee
Member
Member # 5818

 - posted      Profile for Dagonee           Edit/Delete Post 
I would just allow the executable to accept a starting two-letter combination as a parameter, then run the executable once for each core with appropriately-spaced starting letters.

Lazy-man multithreading. [Smile]

Posts: 26071 | Registered: Oct 2003  |  IP: Logged | Report this post to a Moderator
Mucus
Member
Member # 9735

 - posted      Profile for Mucus           Edit/Delete Post 
I suspect that you would just not have written such a program in the first place [Smile]
Posts: 7593 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
It is apparently an assignment, although conceivably the permute-the-alphabet bit was not the teacher's idea.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Qaz
Member
Member # 10298

 - posted      Profile for Qaz           Edit/Delete Post 
I hope you do not find a way to do this, Blayne. Because if you do, the stars might all go out.

http://en.wikipedia.org/wiki/The_Nine_Billion_Names_of_God

Posts: 544 | Registered: Mar 2007  |  IP: Logged | Report this post to a Moderator
Dagonee
Member
Member # 5818

 - posted      Profile for Dagonee           Edit/Delete Post 
We got assigned a permutation calculation that would have resulted in about a megabyte of data once - on trash-80s with 32k and a single floppy drive. But yeah, I doubt the teacher assigned permuting the whole alphabet.
Posts: 26071 | Registered: Oct 2003  |  IP: Logged | Report this post to a Moderator
Bokonon
Member
Member # 480

 - posted      Profile for Bokonon           Edit/Delete Post 
quote:
Originally posted by King of Men:
Or you could write a virus to take over large parts of the Internet for you, making a massively-parallel computer - perfect for this kind of very subdivisible problem - that could do it in a mere million years or so.

No offense to him, but considering Blayne's current programming skills, I think creating said massively-parallel distributed program would take longer than just brute-forcing it.

-Bok

Posts: 7021 | Registered: Nov 1999  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Yup, in fact the assignment explicitely states to use recursion. Which works perfectly but I gave up and stopped running the program as I needed to rerun the program with my comments in it. But ya the teacher only expects us to test 5 letters ABCDE but the assignment include the possibility of permuting the entire alphabet as I have A...Z in an array and I have to input n and the first n letters is whats permuted.
IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Well then, you learned something, to wit "Do complexity analysis before starting program runs." But cheer up, I myself found a stupid, stupid mistake in my code today which has held me up for two weeks by making ten-minute fits run over three days, and get wrong results at that.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Dagonee
Member
Member # 5818

 - posted      Profile for Dagonee           Edit/Delete Post 
O(n!) problems get big very, very quickly.
Posts: 26071 | Registered: Oct 2003  |  IP: Logged | Report this post to a Moderator
BandoCommando
Member
Member # 7746

 - posted      Profile for BandoCommando           Edit/Delete Post 
[Hail] You all impress the heck out of me.

The best I ever got in programming was a modified BASIC on my TI-86 that I used to simplify calculus. Oh, and there was a brief fling with Hypercard scripts in middle school. I used to drive the librarians crazy with scripts that would force restarts after random periods of time elapsed. But then, I would win their adulation and praises by magically 'fixing' the machines.

You all amaze me.

Posts: 1099 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
hehehe.
IP: Logged | Report this post to a Moderator
rollainm
Member
Member # 8318

 - posted      Profile for rollainm   Email rollainm         Edit/Delete Post 
quote:
Originally posted by BandoCommando:
[Hail] You all impress the heck out of me.

The best I ever got in programming was a modified BASIC on my TI-86 that I used to simplify calculus. Oh, and there was a brief fling with Hypercard scripts in middle school. I used to drive the librarians crazy with scripts that would force restarts after random periods of time elapsed. But then, I would win their adulation and praises by magically 'fixing' the machines.

You all amaze me.

Likewise. I wrote a Magic 8 Ball program from scratch on my TI-82 back in 9th grade. [Smile]
Posts: 1945 | Registered: Jul 2005  |  IP: Logged | Report this post to a Moderator
quidscribis
Member
Member # 5124

 - posted      Profile for quidscribis   Email quidscribis         Edit/Delete Post 
42!
Posts: 8355 | Registered: Apr 2003  |  IP: Logged | Report this post to a Moderator
Jutsa Notha Name
Member
Member # 4485

 - posted      Profile for Jutsa Notha Name   Email Jutsa Notha Name         Edit/Delete Post 
quote:
Originally posted by Dagonee:
BTW, if you did this recursively, I see a stack overflow in your future.

If you didn't do this recursively, then either a memory allocation failure or stack overflow is in your future.

Is this a teasing joke? The only way this would happen is if he were to perform the operation sloppily or require the system to count the permutations as they are performed. I can see how creating an overflow would happen with some of the quick and dirty programming that I've seen those who never learned any of the theory, but if this is for a class wouldn't the theory be covered?

This would more likely cause the system to lock up if done poorly.

Posts: 1170 | Registered: Jan 2003  |  IP: Logged | Report this post to a Moderator
Dagonee
Member
Member # 5818

 - posted      Profile for Dagonee           Edit/Delete Post 
Look at his thread on how he planned on doing this. Besides, both classes I've had a permutation assignment for purposes of teaching recursion didn't go into anything about memory management beyond local variable storage prior to that assignment.
Posts: 26071 | Registered: Oct 2003  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
mine were created as the program was run I use 2 pointer char arrays since the size of the array isnt all that definable and they were deleted as the recursive function were popped off the stack.
IP: Logged | Report this post to a Moderator
Dagonee
Member
Member # 5818

 - posted      Profile for Dagonee           Edit/Delete Post 
When you stopped it, how many had it generated?
Posts: 26071 | Registered: Oct 2003  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
How many permutations? well it only really tells me how many when it finishes, stopping the debugger kinda stops it before it can output that part by 9 factorial is around 362,880 possible permuations (took 5 friggin minutes to finish).

Heres ze code.

code:
/*************************************************************

Permuation Assignment
Take an input string N of ABC...XYZ
and print out every permutation
of that input string.

Blayne Bradley
0463737



*************************************************************/


#include <iostream>
#include <cstring>

using namespace std;

//Globals, constants, arrays
const int MAX = 27;
char Beta[MAX];
char Alpha[MAX] = { "ABCDEFGHIJKLMNOPQRSTUWVXYZ" };
char App[MAX] = "\0";

int N = 0;

//Functions
void Perm( char Beta[MAX], char append[MAX] );

void main()
{

int in = 0;

cout << "Please select how many letters you wish to"
<< " permute N: ";
cin >> in; // N

// Error checking
while ( in < 0 || in > 26 )
{

cout << "Invalid Input: Please select how many letters you wish to"
<< " permute N: ";
cin >> in;


}


cout << " N Letters are: ";

// copying the selected N letters into the
// array passed to the Perm function.
for ( int counter = 0; counter < in; counter++)
{
Beta[counter] = Alpha[counter];
// to show the original string
cout << Beta[counter];
}

cout << endl;

cout << "********************************" << endl << endl;

//the Permutation function
Perm(Beta, App);
cout << endl;
cout << N << " Permuations: " << in << " Letters Chosen" << endl << endl;
system("pause");

}
/*
recursively do permutations.
*/
void Perm( char StringB[MAX], char To_App[MAX] )
{
// find the length of the string passed
int len = strlen(StringB);


if ( len > 0 )
{

for ( int count = 0; count < len; count++ )
{
// create a pointer array because length at runtime
// isnt definable so it is more efficient to create
// a pointer array dynamically with a more specific
// size.
char* string1 = new char[len+1];

int counter;
int next;

/* within this loop for the length of the loop
assign letters from StringB -> String1

*/
for ( counter = 0, next = 0; counter < len; counter++, next++ )
{
if ( counter == count )
{
string1[counter] = StringB[++next];
continue;
}
else
{
string1[counter] = StringB[next];
}
}

string1[counter] = '\0'; //appending null value to end of array

int length = strlen(To_App);
char* To_App1 = new char [length+2]; //creating the append pointer array
//dynamically

// copy the passed Append string to the
// new Append string at length size.
strncpy(To_App1, To_App, length );
To_App1[length] = StringB[count];
To_App1[length+1] = '\0';

// Perm calls Perm recursively here
Perm( string1, To_App1 );

// delete the used pointer arrays as you pop off the stack.
delete []string1;
delete []To_App1;

}
}
else
{
// Cout each completed
// Permuation when size is zero.
cout << To_App << endl;

N++;
}
}


IP: Logged | Report this post to a Moderator
vonk
Member
Member # 9027

 - posted      Profile for vonk   Email vonk         Edit/Delete Post 
quote:
Likewise. I wrote a Magic 8 Ball program from scratch on my TI-82 back in 9th grade.
I wrote a pretty neat little maze RPG on my TI-83 in high school. After about 10 minutes of playing you can tell when I got bored because every option leads to a hilarious death.

Other than that, I like to come in these threads and marvel at how little I know about programing. It's a geek to me- err, Greek, that is. [Smile]

Posts: 2596 | Registered: Jan 2006  |  IP: Logged | Report this post to a Moderator
Jutsa Notha Name
Member
Member # 4485

 - posted      Profile for Jutsa Notha Name   Email Jutsa Notha Name         Edit/Delete Post 
Okay, Dagonee, you are correct. That's an overflow waiting to happen. [Smile]
Posts: 1170 | Registered: Jan 2003  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Given that the assignment was to do it recursively, how would you avoid an overflow for any reasonable size of the input?

Which is, by the way, why this is rather a silly way to teach recursion.

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Dagonee
Member
Member # 5818

 - posted      Profile for Dagonee           Edit/Delete Post 
I don't think someone writing this should worry about it too much - as long as safe coding practices are taught eventually, that is.

I would have calculated the number of permutations before making the max 27, though. [Smile]

Posts: 26071 | Registered: Oct 2003  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
max 27 is just the max size of the string, generally i whimsically use 100, 27 seemed better since the alphabet is 26 and i figure 26+1 for the '\0'. absolutely does nothing i think once the first n letters are chosen.
IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Your code took five minutes for 9 characters? I haven't run your code, but I hope not. A naive python implementation takes under 4 seconds without printing, under 40 seconds with calculating, then printing all the output at once, and around a minute and a half printing everything right off.

Here's the slow version (only difference is how/if the printing is done; the function's exactly the same):

code:
#!/usr/bin/env python

import sys

word = sys.argv[1]

def permute(word):
if len(word) == 0:
yield word
else:
for letter_index in range(len(word)):
for permutation in permute(word[:letter_index] + word[letter_index + 1:]):
yield word[letter_index] + permutation

for permutation in permute(word):
print permutation

10 letters does take appreciably longer, though if it doesn't print it only takes around 40 seconds.

Your computer is probably significantly faster than mine, as well.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2