Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: TheQuirk on 1 August 2005, 23:29

Title: Let's play a game, pals.
Post 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.
Title: Re: Let's play a game, pals.
Post by: Laukev7 on 5 August 2005, 00:37
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?
Title: Re: Let's play a game, pals.
Post by: worker201 on 5 August 2005, 00:43
Is there such a thing as an (unreal) integer?
Title: Re: Let's play a game, pals.
Post by: TheQuirk on 5 August 2005, 00:57
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:
+ + * + +
+ * * + -
* * * + +
Title: Re: Let's play a game, pals.
Post by: TheQuirk on 5 August 2005, 01:10
Quote from: worker201
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.
Title: Re: Let's play a game, pals.
Post by: worker201 on 5 August 2005, 01:24
I know what an unreal number is.  I just didn't know there was a special name for an unreal number with integer coefficients.
Title: Re: Let's play a game, pals.
Post by: TheQuirk on 5 August 2005, 01:35
I figured as much. I simply gave the definition to make my post seem bigger. :)
Title: Re: Let's play a game, pals.
Post by: Pathos on 6 August 2005, 05:19
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;
}
Title: Re: Let's play a game, pals.
Post by: solemnwarning on 18 August 2005, 21:31
Challenge #2

make the most compilcated "hello world" program you can

Code: [Select]
#!/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 ;)
Title: Re: Let's play a game, pals.
Post by: skyman8081 on 18 August 2005, 23:48
Quote from: solemnwarning
Challenge #2

make the most compilcated "hello world" program you can

Code: [Select]
#!/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:
Code: [Select]
>+++++++++[<++++++++>-]<.>++++++[<+++++>-]<-.+++++++..++
+.
>>+++++++[<++++++>-]<++.------------.<++++++++.--------.
+++.------.--------.>+.>++++++++++.
Title: Re: Let's play a game, pals.
Post by: worker201 on 19 August 2005, 03:11
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
Title: Re: Let's play a game, pals.
Post by: solemnwarning on 19 August 2005, 13:43
Quote from: skyman8081
The output of that is: "helloworld"

you fail it.

Code: [Select]
#!/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 :)