Skip to content

Instantly share code, notes, and snippets.

@LB--
Created September 3, 2014 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LB--/ca097eb45bc7ef2e1e8d to your computer and use it in GitHub Desktop.
Save LB--/ca097eb45bc7ef2e1e8d to your computer and use it in GitHub Desktop.
Wrote this to speed up my homework solving process instead of using excel.
#include <iostream>
#include <vector>
#include <cmath>
int main()
{
std::vector<long double> v;
{
long double d;
while(std::cin >> d)
{
v.push_back(d);
}
}
long double r = 0.0;
std::size_t const end = std::pow(2u, v.size());
for(std::size_t i = 1; i < end; ++i)
{
long double t = 1.0;
for(std::size_t j = 0; j < v.size(); ++j)
{
if((i >> j) & 1)
{
t *= v[j];
}
else
{
t *= (1.0L - v[j]);
}
}
r += t;
}
std::cout << r << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment