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
def getLudic ( n ) : NEW_LINE INDENT ludics = [ ] NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT ludics . append ( i ) NEW_LINE DEDENT index = 1 NEW_LINE while ( index != len ( ludics ) ) : NEW_LINE INDENT first_ludic = ludics [ index ] NEW_LINE remove_index = index + first_ludic NEW_LINE while ( remove_index < len ( ludics ) ) : NEW_LINE INDENT ludics . remove ( ludics [ remove_index ] ) NEW_LINE remove_index = remove_index + first_ludic - 1 NEW_LINE DEDENT index += 1 NEW_LINE DEDENT return ludics NEW_LINE DEDENT n = 25 NEW_LINE print ( getLudic ( n ) ) NEW_LINE