Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:38:06+00:00 2026-05-31T17:38:06+00:00

I’m currently in the process of solving euler problems to improve in Haskell. Though,

  • 0

I’m currently in the process of solving euler problems to improve in Haskell. Though, my attempt at solving problem n° 43 produces no output.

Just to be clear, I’m not asking for help on the “problem algorithmic” part, even if I’m wrong. I’m specifically asking for help on the Haskell part.

So, I divided my attempt into simple functions. First I build a list holding all 0-9pandigital numbers, then I define functions to cut those numbers into the interesting part and finally I filter only the correct ones:

import Data.List
main = print $ foldl1 (+) goodOnes

pands = [read x :: Integer | x <- permutations "0123456789", head x /= '0']

cut3from :: Integer -> Integer -> Integer
cut3from x n = mod (div x nd) 1000
    where
        l = fromIntegral $ length $ show x :: Integer
        nd = 10 ^ (l - 3 - n)

cut :: Integer -> [Integer]
cut x = map (cut3from x) [1..7]

testDiv :: Integral a => [a] -> Bool
testDiv l = and zipped
    where
        zipped = zipWith mult l [2, 3, 5, 7, 11, 13, 17]

mult :: Integral a => a -> a -> Bool
mult a b = mod a b == 0

goodOnes = filter (testDiv.cut) pands

Though, when compiling it (with -O2) and executing it, it outputs nothing. Even with +RTS -s.

I’d like advice on two points mainly:

  • why is this code wrong, how to improve it
  • how could I have debugged it myself
  • as a side point, if you have advice on how to handle Integer and Ints easily, please post them. I find it troublesome to use both together.

But any other remark is welcome!

EDIT: it seems that GHCi slowly builds the result list goodOnes and is able to answer after a long time (only in GHCi, when compiled it’s still as reported). That’s certainly not a behaviour I can wish to observ in my programs. How could I fix that ?

EDIT2: it now works when compiled too (code unchanged). I’m puzzled about all those inconsistencies and would welcome any explanation!

EDIT3: semihappy ending: after a reboot, all went back to normal ~~

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:38:08+00:00Added an answer on May 31, 2026 at 5:38 pm

    To answer “how could I have debugged it myself”:

    Check out ghci.

    prompt$ ghci
    GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
    Loading package ghc-prim ... linking ... done.
    Loading package integer-gmp ... linking ... done.
    Loading package base ... linking ... done.
    Loading package ffi-1.0 ... linking ... done.
    Prelude> 
    

    It’s an interactive interpreter that allows you to:

    • load files and play with the contents

      Prelude> :load myfile.hs 
      [1 of 1] Compiling Main             ( myfile.hs, interpreted )
      Ok, modules loaded: Main.
      *Main> xyz "abc"
      *Main> 3
      
    • type in definitions and use them

      *Main> let f x = x + 3
      
    • evaluate expressions and see the results

      *Main> f 14
      17
      
    • inspect types and kinds

      *Main> :t f
      f :: (Num a) => a -> a
      
      *Main> :k Maybe
      Maybe :: * -> *
      

    Make sure you test each of the little pieces before you test the whole shebang — it’s easier to find problems in small things than in big ones. Check out QuickCheck if you’re into unit tests.

    For the Ints vs. Integers issue, you could sidestep the issue by only using Integers (of course, they may be less efficient: YMMV). Data.List has functions prefixed with generic, i.e. genericLength which are quite useful.


    Here’s how I compiled and ran it:

    prompt$ ghc euler43.hs
    prompt$ ./a.out
    <some number is printed out>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.