Code Inefficiency?
Page 1 of 1
Code Inefficiency?
So, it occurs to me, my code may be a bit inefficient... Has been running for 17hours now... If I was less lazy, and not too far in I would quickly rewrite it, but I'll probably do it anyways. 'tis solving the Lattice Paths problem on Project Euler, I know a considerably easier way to solve it, but I wanted to do it a unique way.
- Code:
//Lattice Paths
#include <iostream>
extern "C"
{
#include <pthread.h> //Not Used, was going to multithread, but could remember how at the time.
#include <unistd.h>
}
using namespace std;
bool checkBin(unsigned long long bin, int x)
{
bool buffer[32] = {0};
int i = 0;
int count = 0;
while(bin > 0)
{
if(bin % 2 != 0)
{
buffer[i] = 1;
}
else
{
buffer[i] = 0;
}
bin /= 2;
i++;
}
for(int i = 0; i < 32; i++)
{
count += buffer[i];
}
if(count == x)
{
return true;
}
return false;
}
int main()
{
int x;
unsigned long long count = 0;
cout << "Enter Size of Grid: ";
cin >> x;
unsigned long long bufBin = (pow(2, x) - 1);
for(unsigned long long i = 0; i < bufBin; i++)
{
count += checkBin(i, x);
}
cout << (count * 2) + 2;
return 0;
}
Gecko- Tier 4 (500 posts)
Similar topics
» Python code
» Need someone to code a program for me in C#
» Forum Code Issues
» E-Voucher Code - PM - Exchange PM - WMZ - EGOPAY - MB - BTC
» 14 day xbox live code for sale
» Need someone to code a program for me in C#
» Forum Code Issues
» E-Voucher Code - PM - Exchange PM - WMZ - EGOPAY - MB - BTC
» 14 day xbox live code for sale
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|