Skip to content

Instantly share code, notes, and snippets.

@shaswatsaxena
Created July 1, 2019 05:58
Show Gist options
  • Save shaswatsaxena/3ca99cf628f6416c2f65480421d399de to your computer and use it in GitHub Desktop.
Save shaswatsaxena/3ca99cf628f6416c2f65480421d399de to your computer and use it in GitHub Desktop.
Paper Folding in minimum moves
function minMoves (h,w,h1,w1) {
let moves = 0;
while (h != h1 || w != w1){
moves++;
if ( h > h1 ) {
let hFold = h - h1;
if (hFold > Math.floor(h/2)) {
hFold = Math.floor(h/2);
}
h = h - hFold;
continue;
}
if ( w > w1 ) {
let wFold = w - w1;
if (wFold > Math.floor(w/2)) {
wFold = Math.floor(w/2);
}
w = w - wFold;
}
}
return moves;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment