Skip to content

JavaScript Version #1

Open
Open
@bringforthjoy101

Description

@bringforthjoy101
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()));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions