Múltiplos con ceros y unos
Se observa que todos los primeros números naturales tienen al menos un múltiplo no nulo que está formado solamente por ceros y unos. Por ejemplo, 1×10=10, 2×5=10, 3×37=111, 4×25=100, 5×2=10, 6×185=1110; 7×143=1001; 8X125=1000; 9×12345679=111111111.
Definir la función
1 |
multiplosCon1y0 :: Integer -> [Integer] |
tal que (multiplosCon1y0 n) es la lista de los múltiplos de n cuyos dígitos son 1 ó 0. Por ejemplo,
1 2 3 |
take 4 (multiplosCon1y0 3) == [111,1011,1101,1110] take 3 (multiplosCon1y0 23) == [110101,1011011,1101010] head (multiplosCon1y0 1234658) == 110101101101000000110 |
Comprobar con QuickCheck que todo entero positivo tiene algún múltiplo cuyos dígitos son 1 ó 0.
Soluciones
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import Test.QuickCheck multiplosCon1y0 :: Integer -> [Integer] multiplosCon1y0 n = [x | x <- numerosCon1y0, x `rem` n == 0] -- numerosCon1y0 es la lista de los números cuyos dígitos son 1 ó 0. Por -- ejemplo, -- ghci> take 15 numerosCon1y0 -- [1,10,11,100,101,110,111,1000,1001,1010,1011,1100,1101,1110,1111] numerosCon1y0 :: [Integer] numerosCon1y0 = 1 : concat [[10*x,10*x+1] | x <- numerosCon1y0] -- La propiedad es prop_existe_multiplosCon1y0 :: Integer -> Property prop_existe_multiplosCon1y0 n = n > 0 ==> multiplosCon1y0 n /= [] -- La comprobación es -- ghci> quickCheck prop_existe_multiplosCon1y0 -- +++ OK, passed 100 tests. |
No se me ocurre ninguna forma mejor que revisar linealmente.