Friday, 15 March 2013

haskell - Check if number contains all digits -


What is the effective way to check, in what number does all the numbers in Haskell include? Modified lists are very inefficient, so keeping in mind the number of occurrences of each issue is not well. You can only place 10 boolean variables in the recursion, in which you go through the list of digits of your number, but it seems that it is very ugly.

There is no reason that a list is very inefficient for your purpose. You can use a set to keep track of the digits you saw.

  Import data List Importable Data. S Issue as Set = Folder Associate Assimmeter. Go unfoldr go where 0 = nothing go = n = let (a, b) = n `divMod` in 10 bus (b, a) is all10digits = (== (s from list [0..9])) For digit  

inserted is Data.Set is O (log n), but the set you are joining with There will never be more than 10 elements, so these summaries are essentially time consuming.


No comments:

Post a Comment