-
04-16-2004, 08:59 AM
#166
here's a fun one for any computer/math nerd, how about a virtual enigma? no need for a plugboard, but 3 encoding disks plus the reflection disk.
FYI - for those who don't know the Enigma was a German encryption machine used in WWII. But it's relatively simple in construct.
if (i_forgot && this_is_about_code)
language = c++;
-
04-16-2004, 02:13 PM
#167
Scotty: Captain, we din' can reference it!
Kirk: Analysis, Mr. Spock?
Spock: Captain, it doesn't appear in the symbol table.
Kirk: Then it's of external origin?
Spock: Affirmative.
Kirk: Mr. Sulu, go to pass two.
Sulu: Aye aye, sir, going to pass two.
-
04-16-2004, 02:56 PM
#168
Hey now, is that yours or are you just showing someone else's final project?
A lot of these challenges have already been done, like the next perm one I did around the beginning of last year. But it gives people who want a challenge something to do....like myself.
if (i_forgot && this_is_about_code)
language = c++;
-
04-16-2004, 05:38 PM
#169
Oops, sorry, I didn't mean to give the impression that that was mine. Never mind. I'll go away now.
Scotty: Captain, we din' can reference it!
Kirk: Analysis, Mr. Spock?
Spock: Captain, it doesn't appear in the symbol table.
Kirk: Then it's of external origin?
Spock: Affirmative.
Kirk: Mr. Sulu, go to pass two.
Sulu: Aye aye, sir, going to pass two.
-
11-12-2004, 01:12 PM
#170
-
11-13-2004, 11:43 AM
#171
#include <iostream>
#include <string>
#include <time>
#include <math>
#include <vector>
#include <fstream>
using namespace std;
void error(const char*p, const char *p2="")
{
cerr << p << " " << p2 << "\n";
exit(1);
}
int main(int argc, char *argv[])
{
vector<string> quotes(0);
int items=0;
string q;
if (argc < 2)
error("no filename given");
ifstream file(argv[1]);
if(!file)
error("can't open", argv[1]);
char ch;
while (file.get(ch)) {
if (ch=='\n'){
if(items % 100 == 0)
quotes.resize(quotes.size()+100); //increase the size of the vector
quotes[items++]=q;
q="";
}else
q+=ch;
}
int n;
srand(time(0));
n=rand()%items;
cout << quotes[n] <<endl;
return 0;
}
<><
-
11-14-2004, 03:35 AM
#172
Originally posted by Enlighted One
Random Quote program
Code:
#!/bin/bash
# pass the file with quotes as an argument
# range = the lenth of quote file
range=`cat $1 | wc -l`
# line = a random number between one and range
let "line=($RANDOM%$range)+1"
# output the random line
sed $line'!d' $1
Can it get any simpler than that?
I must admit that I'm pretty proud of myself.
Now somebody else will come along and make it simpler... heheh
-
11-14-2004, 02:34 PM
#173
-
11-17-2004, 10:46 PM
#174
damn I love slackware.... making program challenges easier every day.
Registered Linux User: #342515
Slackware 10 - kernel 2.6.10
AMD Athlon 3000+
512 RAM pc2700
NVIDIA GeForce2 Integrated
www.rex-pro.com For life!!!
-
11-20-2004, 04:17 PM
#175
There's a theorem from graph theory that sums this um very nicely, no need to do brute search methods...
::goes to track down his graph theory book::
darn can't find it. Something to do with the degree of every vertex added together is 2 times the total number of edges. Therefore when doing person-person relationships, it's only possible for an even amount (it's impossible for there to be 7 people at a party and each one to know exactly 3 others).
Something like that
Originally posted by duncanbojangles
Okay, I read this book "Archimede's Revenge" a couple weeks ago and it has a buttload of stuff like this, basically all this number and geometry thoery and stuff. Good reading. Here's one of the problems:
"Suppose there are 100 people in a group, and you want to find out if 50 of them know each other".
This can be done on paper by drawing 100 dots, connecting lines between people that know each other, and looking for all the people that know 49 others that all know the other 49.
Yeah, it's one of those problems that as the set of people gets larger, the amount of work that it would require to find the answer increases exponentially.
Find an algorithm that finds the answer in a manner such that the answer is found in an amount of work like n * number of people, rather than number of people ^ n.
I was working on a method where you make a table, with all the people in the columns and all the people in the rows. Mark an X in the appropriate spot where people know one another(including that person knowing themself). Then remove all people that have less than the needed number of associations. Then you are left with all the people knowing the amount of people needed to associate with. Then, if all the spaces are filled, the answer is 'yes', they all know each other. I belive this approach is not exponential, but I could be wrong.
-
11-21-2004, 02:30 AM
#176
Originally posted by grady
You can waste alot of multiplications evaluating a polynomial such as a x^3+b x^2+ c x + d , but its possible to evaluate an n degree polynomial with only n multiplications. Can you figure it out? Don't forget that computing x^3 takes 3 multiplications in itself.
Don't know if it has been said before, and I am really late on this thread...but anyway. Just learned how to do this in high school....
say z is what you are evaluating for
ax^3+bx^2+cx+d
a*z = m
m+b = n
n*z = o
o+c = p
p*z = q
q+d = r
and r is the answer.
example-
2x^3+x^3+4x+2
For 3
putting it in = 77
2 * 3 = 6
6 + 1 = 7
7 * 3 = 21
21 + 4 = 25
25 * 3 = 75
75 + 2 = 77
Anyway, it was probably already done, and I probably explained it way too much...but I'm bored anyway .
Last edited by gobeavers; 11-21-2004 at 02:32 AM.
-
11-21-2004, 03:02 PM
#177
Originally posted by gobeavers
say z is what you are evaluating for
ax^3+bx^2+cx+d
a*z = m
m+b = n
n*z = o
o+c = p
p*z = q
q+d = r
and r is the answer.
So in other words, you "factor" ax^3 + bx^2 + cx + d into:
(((ax + b)x + c)x + d
It's not a true factorization, but it does reduce into n multiplications.
(FWIW: This question was asked so long ago that I don't remember if there was an answer to it posted already either! )
-
11-21-2004, 05:40 PM
#178
Originally posted by bwkaz
So in other words, you "factor" ax^3 + bx^2 + cx + d into:
(((ax + b)x + c)x + d
It's not a true factorization, but it does reduce into n multiplications.
(FWIW: This question was asked so long ago that I don't remember if there was an answer to it posted already either! )
I don't konw...its something called "synthetic substitution" using some guys root theorem (or something like that)....we just learned it in pre-calc.
Basically, you divide the polynomial by x-z, z being what you are evaluating for, and the remainder is the answer.
-
11-30-2004, 01:01 PM
#179
This piece of code is awesome! Compile it and run it!
//The Beapanator!!!!!!!
#include <iostream>
using namespace std;
int main()
{
int w, n;
char y;
cout << "Would you like to annoy the people around you?";
cin >> y;
if(y=='y')
{
cout << "How many times?";
cin >> n;
for(n; n!=0; n--)
{
cout << "\a";
}
}
else
return 0;
}
<><
-
12-01-2004, 08:17 AM
#180
Enlighted One:
using namespace std;
bwkaz, don't you have anything to say about this?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|