Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript Version #1

Open
bringforthjoy101 opened this issue Sep 29, 2022 · 0 comments
Open

JavaScript Version #1

bringforthjoy101 opened this issue Sep 29, 2022 · 0 comments

Comments

@bringforthjoy101
Copy link

function ChessboardTraveling(str) { 
  const splittedString = str.split('')
  const x = Number(splittedString[1]), y = Number(splittedString[3])
  const a = Number(splittedString[6]), b = Number(splittedString[8])
  const rightPath = a - x, upPath = b - y
  const totalPath = rightPath + upPath
  const totalStepPermutation = travel(totalPath)
  const upPathPermutation = travel(upPath)
  const rightPathPermutation = travel(rightPath)
  const possibleSteps = Number(totalStepPermutation / (upPathPermutation * rightPathPermutation))
  return possibleSteps; 

}

const travel = (num) =>{
  let result = 1
  for (let i = 1; i<num+1; i++) {
    result = result * i
  }
  return result
}
   
// keep this function call here 
console.log(ChessboardTraveling(readline()));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant