Author Topic: Let's play a game, pals.  (Read 2100 times)

TheQuirk

  • VIP
  • Member
  • ***
  • Posts: 2,154
  • Kudos: 315
Let's play a game, pals.
« 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.
« Last Edit: 2 August 2005, 03:07 by TheQuirk »

Laukev7

  • VIP
  • Member
  • ***
  • Posts: 2,834
  • Kudos: 495
Re: Let's play a game, pals.
« Reply #1 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?

worker201

  • Global Moderator
  • Member
  • ***
  • Posts: 2,810
  • Kudos: 703
    • http://www.triple-bypass.net
Re: Let's play a game, pals.
« Reply #2 on: 5 August 2005, 00:43 »
Is there such a thing as an (unreal) integer?

TheQuirk

  • VIP
  • Member
  • ***
  • Posts: 2,154
  • Kudos: 315
Re: Let's play a game, pals.
« Reply #3 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:
+ + * + +
+ * * + -
* * * + +

TheQuirk

  • VIP
  • Member
  • ***
  • Posts: 2,154
  • Kudos: 315
Re: Let's play a game, pals.
« Reply #4 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.

worker201

  • Global Moderator
  • Member
  • ***
  • Posts: 2,810
  • Kudos: 703
    • http://www.triple-bypass.net
Re: Let's play a game, pals.
« Reply #5 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.

TheQuirk

  • VIP
  • Member
  • ***
  • Posts: 2,154
  • Kudos: 315
Re: Let's play a game, pals.
« Reply #6 on: 5 August 2005, 01:35 »
I figured as much. I simply gave the definition to make my post seem bigger. :)

Pathos

  • Member
  • **
  • Posts: 518
  • Kudos: 416
Re: Let's play a game, pals.
« Reply #7 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;
}

solemnwarning

  • Member
  • **
  • Posts: 747
  • Kudos: 338
    • http://www.solemnwarning.net
Re: Let's play a game, pals.
« Reply #8 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 ;)
-----BEGIN GEEK CODE BLOCK-----
 Version: 3.1
 GCS/CM d- s+:+ a--- C++ UL++++>$ P+ L+++ !E W++ !N !o !K-- w !O !M !V PS+ PE- !Y !PGP !t !5 !X !R tv b+ DI+ !D G e- h !r y-
 ------END GEEK CODE BLOCK------

skyman8081

  • VIP
  • Member
  • ***
  • Posts: 910
  • Kudos: 187
    • http://sauron.game-host.org/
Re: Let's play a game, pals.
« Reply #9 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]
>+++++++++[<++++++++>-]<.>++++++[<+++++>-]<-.+++++++..++
+.
>>+++++++[<++++++>-]<++.------------.<++++++++.--------.
+++.------.--------.>+.>++++++++++.
2 motherfuckers have sigged me so far.  Fuck yeah!



solemnwarning

  • Member
  • **
  • Posts: 747
  • Kudos: 338
    • http://www.solemnwarning.net
Re: Let's play a game, pals.
« Reply #11 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 :)
-----BEGIN GEEK CODE BLOCK-----
 Version: 3.1
 GCS/CM d- s+:+ a--- C++ UL++++>$ P+ L+++ !E W++ !N !o !K-- w !O !M !V PS+ PE- !Y !PGP !t !5 !X !R tv b+ DI+ !D G e- h !r y-
 ------END GEEK CODE BLOCK------