Problem
Have the function
ChessboardTraveling(str)
readstr
which will be a string consisting of the location of a space on a standard 8x8 chessboard with no pieces on the board along with another space on the chessboard.The structure of
str
will be the following:\$(x,y)(a,b)\$ where \$(x, y)\$ represents the position you are currently on with \$x\$ and \$y\$ ranging from 1 to 8 and \$(a, b)\$ represents some other space on the chessboard with \$a\$ and \$b\$ also ranging from 1 to 8 where \$a > x\$ and \$b > y\$. Your program should determine how many ways there are of traveling from \$(x, y)\$ on the board to \$(a, b)\$ moving only up and to the right.
Example: if
str
is \$(1,1)(2, 2)\$ then your program should output2
because there are only two possible ways to travel from space \$(1, 1)\$ on a chessboard to space \$(2, 2)\$ while making only moves up and to the right.
Are there any improvements I can make?
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>
std::string delete_Punctuation(std::string& str)
{
std::string noPunctString = "";
str.insert(str.length()/2," ");
for (auto character : str)
{
if (!ispunct(character))
{
noPunctString.push_back(character);
}
}
return str = noPunctString;
}
bool check_If_PointXY_Is_Less_Than_PointAB(std::vector<int> v)
{
return (v.at(2) > v.at(0) && v.at(3) > v.at(1));
}
long long int find_Factorial(unsigned int n)
{
if (n == 0)
{
return 1;
}
return n * find_Factorial(n - 1);
}
int number_Of_Steps(std::string& str)
{
str = delete_Punctuation( str );
std::istringstream iss( str );
std::vector<int> coll((std::istream_iterator<int>( iss )),std::istream_iterator<int>());
int steps = 0;
if (check_If_PointXY_Is_Less_Than_PointAB(coll))
{
int xDistance = coll.at(2) - coll.at(0);
int yDistance = coll.at(3) - coll.at(1);
int totalDistance = xDistance + yDistance;
//combination formula
steps = find_Factorial(totalDistance)/(find_Factorial(xDistance) * (find_Factorial(totalDistance - xDistance)));
}
return steps;
}