21 Matchsticks Problem | Function to return the optimal strategy ; Removing matchsticks in blocks of five ; Driver code
function TwentyoneMatchstick ( arr , N ) { for ( var i = 0 ; i < N ; i += 1 ) { document . write ( 5 - arr [ i ] + " " ) ; } document . write ( " " ) ; } var arr = [ 3 , 4 , 2 , 2 ] ; var N = arr . length ; TwentyoneMatchstick ( arr , N ) ;