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 7430961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:13:18+00:00 2026-05-29T09:13:18+00:00

In trying to increase my Haskell knowledge I thought I’d try and get the

  • 0

In trying to increase my Haskell knowledge I thought I’d try and get the 12th Project Euler problem solved using the State Monad. It seemed to make sense to me at the time to incorporate the whole triangle number creation with putting it in state.

Here is my code:

module Main where

import Control.Monad
import Control.Monad.State

type MyState = (Integer, Integer)
s0 = (7, 28)

tick :: State MyState Int
tick = do 
    (n,o) <- get
    let divs = getDivLen (n,o)
    if divs >= 500
        then do
            let n' = n + 1
            let o' = o + n'
            put (n', o')
            tick
        else
            return divs

getDivLen :: MyState -> Int
getDivLen (n,o) = foldl1 (+) [2 | x <- [1..x], o `mod` x == 0]
    where x = round . sqrt $ fromIntegral o

main :: IO ()
main = print $ evalState tick s0

The code compiles and I get the result 6 to the console. I’m just not sure what I’m doing wrong to not have the recursion happen.

Thanks in advance.

  • 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-29T09:13:19+00:00Added an answer on May 29, 2026 at 9:13 am

    Looks like you have your loop condition backwards. You’re only recursing if you’ve found a triangle number with at least 500 divisors, so it will of course stop immediately since the first one has fewer than that.

    To fix this, change the line if divs >= 500 to if divs < 500.

    Once you’ve done that, you’re supposed to return the number itself, not the number of divisors, so you’ll have to fix the return divs as well. I’ll leave fixing that part to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decrease or increase the value in a textbox using javascript. I
When I am trying to create a table using NDB storage engine I get
I am trying to increase my knowledge of linq so I would like to
I'm trying to have atomic increase-or-create operation in Django cache. I'm using memcache as
I'm trying to increase the timeout on all sessions. The site is hosted with
I'm trying to increase the number of items shown in the Run MRU list.
I am trying to increase the size of the image by 20. So I
I'm currently debugging some fairly complex persistence code, and trying to increase test coverage
Trying to get my css / C# functions to look like this: body {
Trying to keep all the presentation stuff in the xhtml on this project and

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.