Skip to content

Instantly share code, notes, and snippets.

@mura303
Created January 10, 2013 14:11
Show Gist options
  • Save mura303/4502266 to your computer and use it in GitHub Desktop.
Save mura303/4502266 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct Animal
{
int feet;
int bill;
int tail;
};
Animal duck = { 2, 1, 0 };
Animal beaver = { 4, 0, 1 };
Animal platypus = { 4, 1, 1 };
int minimumAnimals( int webbedFeet, int duckBills, int beaverTails )
{
int i, j, k;
for( i=0; i<=1000; i++ ) // duck
{
for( j=0; j<=1000; j++ ) // beaver
{
for( k=0; k<=1000; k++ ) // platypus
{
if( duck.feet*i + beaver.feet*j + platypus.feet*k == webbedFeet &&
duck.bill*i + beaver.bill*j + platypus.bill*k == duckBills &&
duck.tail*i + beaver.tail*j + platypus.tail*k == beaverTails )
{
goto found;
}
}
}
}
found:
return i+j+k;
}
int main()
{
cout << minimumAnimals( 10, 2, 2 ) << endl;
cout << minimumAnimals( 1000, 200, 200 ) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment