Kaderudo 0 Denunciar mensagem Publicado 11 de Janeiro de 2010 Boas, no outro dia o meu professor mandou fazer este problema mas ainda não percebo muito de Haskell, e agradecia que me ajudassem com esta, não gosto muito de pedir ajuda nos exercícios das aulas, mas estou mesmo bloqueado. Vangelis the bear wants his older bear brother Mitsos to give him some of the honey he just brought to the cave, but Mitsos is a geek and, instead of just giving it to his brother, he asked him to solve a quiz for him in order to win the honey. The quiz is to find how many multiples of a given number exist that are greater or equal to another number and less or equal to a third number and whose decimal representation contains only certain digits. Unfortunately, Vangelis is not that good at math and cannot figure this quiz out. Task Your task is to help Vangelis by writing a function which, given an positive integer, an integer interval and a set of decimal digits, computes the number of numbers from the interval that are multiples of the given positive integer and whose decimal representation uses only digits from the given set. Function The functions shall be called vangelis and its signature must be as follows: vangelis :: Int -> Int -> Int -> Int -> Int The first argument represents the number whose multiples we consider. The second argument represents the lower bound of the interval. The third argument represents the upper bound of the interval. The fourth argument represents the set of digits, as follows: a digit is in the set if and only if it appears in the decimal representation of the fourth argument. The first argument is positive and the other three are positive or zero. Examples Main> vangelis 6 1 50 2468 4 Main> vangelis 7 35 91 135797531 3 Main> vangelis 2 1 100 13579 0 Main> vangelis 5 1 100 1234567890 20 Main> vangelis 5 1 10000 1234567890 2000 Muito Obrigado Partilhar esta mensagem Ligação para a mensagem Partilhar noutros sites
Rui Carlos 348 Denunciar mensagem Publicado 11 de Janeiro de 2010 Começa por tentar encontrar os múltiplos (até ao máximo valor dado). A notação [n1,n2..n3] para a definição de listas é capaz de ter ser útil. Depois podes eliminar os números menores do que o mínimo. Por fim irás ter que fazer uma função para verificar se os algarismos de um número estão numa lista previamente dada. Converter o número para uma string, em conjunto com a função de intersecção de conjuntos (disponível no módulo List), deve facilitar a tarefa. Rui Carlos Gonçalves Partilhar esta mensagem Ligação para a mensagem Partilhar noutros sites