Stop Microsoft
Miscellaneous => Programming & Networking => Topic started by: TheQuirk on 1 August 2005, 23:29
-
In this thread, I'm going to post various programming challenges. Today I'll post one. Once somebody solves it, I'll post another one. Use whatever programming/scriping language you want--this isn't the IOI!
Challenge #1:
The program is given the (real) integers a, b, c, d, e, f and g, and the identity (a?b)?c)?d)?e)?f = g.
The program's goal is to find which arthimetic operators need to replace each question mark in order to make said identity true. If the task is impossible, output an error message of some sort.
Edit: by "arthimetic operators" I mean addition, subtraction, multiplication and division.
-
I know you've explained this to me in private, but can you clarify the rules of the game?
It seems to me that anyone with basic knowledge of mathematics can tell that almost any mathematical operators could be used in almost any order, since none of the variables have been defined. Or are you asking us to implement a program that would find every possible arrangement of operators?
-
Is there such a thing as an (unreal) integer?
-
One solution is enough.
For example, let's say that you're given the integers 1, 2, 3, 4, 5, 6 and 35.
Any of the following solutions would be correct:
+ + * + +
+ * * + -
* * * + +
-
Is there such a thing as an (unreal) integer?
Yes; such integers are called Gaussian integers. Gaussian integers are complex numbers in the form of a+bi where a and b are integers.
-
I know what an unreal number is. I just didn't know there was a special name for an unreal number with integer coefficients.
-
I figured as much. I simply gave the definition to make my post seem bigger. :)
-
5min to write 10min to debug.
#include
#include
#include
using namespace std;
typedef vector IntList;
int result;
IntList nums;
void Test(IntList::iterator i, int value, string s = "")
{
if (i == nums.end())
{
if (value == result) cout << s << endl;
return;
}
Test(i + 1, value + (*i), s+"+ ");
Test(i + 1, value - (*i), s+"- ");
Test(i + 1, value / (*i), s+"/ ");
Test(i + 1, value * (*i), s+"* ");
return;
}
int main(int argc, char ** argv)
{
nums.resize(6);
for (int i = 0; i < 6; i++)
cin >> nums;
cin >> result;
cout << endl;
Test(nums.begin()+1,nums[0]);
return 0;
}
-
Challenge #2
make the most compilcated "hello world" program you can
#!/usr/bin/perl
$hello = "hello";
$world = "world";
$hiworld = "$hello"."$world";
open(TXT, ">/tmp/helloworld");
print TXT "$hiworld";
close(TXT);
system("/bin/cat /tmp/helloworld");
system("/bin/rm -f /tmp/helloworld");
if some1 makes a more complicated post ill make more ;)
-
Challenge #2
make the most compilcated "hello world" program you can
#!/usr/bin/perl
$hello = "hello";
$world = "world";
$hiworld = "$hello"."$world";
open(TXT, ">/tmp/helloworld");
print TXT "$hiworld";
close(TXT);
system("/bin/cat /tmp/helloworld");
system("/bin/rm -f /tmp/helloworld");
if some1 makes a more complicated post ill make more ;)
The output of that is: "helloworld"
you fail it.
and, in BrainFuck:
>+++++++++[<++++++++>-]<.>++++++[<+++++>-]<-.+++++++..++
+.
>>+++++++[<++++++>-]<++.------------.<++++++++.--------.
+++.------.--------.>+.>++++++++++.
-
Dumb game, as this one is clearly the winner:
http://www2.latech.edu/~acm/helloworld/visualc++.html
Runner ups:
http://www2.latech.edu/~acm/helloworld/Intercal.html
http://www2.latech.edu/~acm/helloworld/asm370.html
http://www2.latech.edu/~acm/helloworld/c.html
http://www2.latech.edu/~acm/helloworld/cobol.html
-
The output of that is: "helloworld"
you fail it.
#!/usr/bin/perl
$hello = "hello";
$world = "world";
$hiworld = "$hello"." "."$world";
open(TXT, ">/tmp/helloworld");
print TXT "$hiworld";
close(TXT);
system("/bin/cat /tmp/helloworld");
system("/bin/rm -f /tmp/helloworld");
fixed :)