Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Kaderudo

Duvida Problema em Haskell

Recommended Posts

Kaderudo

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

Share this post


Link to post
Share on other sites
Rui Carlos

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.