Guai Lists X45171


Statement
 

pdf   zip

We say that a list ff is nn-guai if all the elements in ff that are in positions multiples of nn are themselves multiples of nn. For example, f=[0,1,2,3,4,5,10,10,10,10,25,11]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]=0f[0] = 0, f[5]=5f[5] = 5, and f[10]=25f[10] = 25, are also multiples of 5. Instead, f=[0,1,2,3,4,8]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 ff of non-negative integers and an integer nn greater than zero returns boolean True if ff is nn-guai and False otherwise.

Sample session

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