Guai Lists X45171


Statement
 

pdf   zip

html

We say that a list f is n-guai if all the elements in f that are in positions multiples of n are themselves multiples of n. For example, f = [0,1,2,3,4,5,10,10,10,10,25,11] is 5-guai, because in positions 0, 5 and 10 (which are multiples of 5) the elements f[0] = 0, f[5] = 5, and f[10] = 25, are also multiples of 5. Instead, f = [0,1,2,3,4,8] is not 5-guai because in position 5 which is multiple of 5 there is an 8 that is not multiple of 5.

Implement the function is_n_guai (f, n) that given a list f of non-negative integers and an integer n greater than zero returns boolean True if f is n-guai and False otherwise.

Sample session
>>> is_n_guai([0,1,2,3,4,5,10,10,10,10,25,11],5)
True
>>> is_n_guai([0,1,2,3,4,8],5)
False
>>> is_n_guai([2,2,4,8,10,12],2)
True
Information
Author
InfBesos
Language
English
Other languages
Catalan Spanish
Official solutions
Python
User solutions
Python