Created
July 1, 2019 05:58
-
-
Save shaswatsaxena/3ca99cf628f6416c2f65480421d399de to your computer and use it in GitHub Desktop.
Paper Folding in minimum moves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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