Ludic Numbers | Returns a list containing all Ludic numbers smaller than or equal to n . ; ludics list contain all the ludic numbers ; Here we have to start with index 1 and will remove nothing from the list ; Here first item should be included in the list and the deletion is referred by this first item in the loop . ; remove_index variable is used to store the next index which we want to delete ; removing the next item ; remove_index is updated so that we get the next index for deletion ; Driver code
function getLudic ( n ) { let ludics = [ ] ; for ( let i = 1 ; i <= n ; i ++ ) ludics . push ( i ) ; for ( let index = 1 ; index < ludics . length ; index ++ ) { let first_ludic = ludics [ index ] ; let remove_index = index + first_ludic ; while ( remove_index < ludics . length ) { ludics . splice ( remove_index , 1 ) ; remove_index = remove_index + first_ludic - 1 ; } } return ludics ; } let n = 25 ; document . write ( getLudic ( n ) ) ;