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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:14:38+00:00 2026-05-20T05:14:38+00:00

For a little context, i’m trying to solve Project Euler problem 31 using excellent

  • 0

For a little context, i’m trying to solve Project Euler problem 31 using excellent GParsPool Fork/Join support.

For that, i’ve written the foolowing code :

import groovyx.gpars.*
import groovy.util.GroovyCollections

@Grab(group="org.codehaus.gpars", module="gpars", version="0.11")
def getMatchingCombos(target) {
    combos = [200, 100 /*, 50, 20, 10, 5, 2, 1*/]
    GParsPool.withPool(1) { pool ->
        combos = combos.collectParallel { n ->  
            ((0..(target/n)).step(1) as TreeSet).collect { p -> p*n }
        }
        return GParsPool.runForkJoin(combos, 0, 0, target) { usableCombos, comboIndex, sum, targetSum ->
            def offset = "\t"*comboIndex
            def results = 0
            if(sum<=targetSum) {
                if(comboIndex<combos.size()) {
                    usableCombos[comboIndex].each { n ->
                        println offset+"now trying with $comboIndex element value $n (curent sum is $sum)"
                        results += forkOffChild(usableCombos, comboIndex+1, sum+n, targetSum)
                    }
                } else {
                    if(sum==targetSum) {
                        results +=1
                        println offset+"sum is target ! so we have $results"
                    }
                }
            }
            return results;
        }
    }
}

println getMatchingCombos(200)

Unfortunatly, each time I try to run this, I get the following stack trace :

now trying with 0 element value 0 (curent sum is 0). Known combos are [[0, 200], [0, 100, 200]] and target is 200
        now trying with 1 element value 0 (curent sum is 0). Known combos are [[0, 200], [0, 100, 200]] and target is 20
0
Caught: java.util.concurrent.ExecutionException: java.lang.NullPointerException
        at groovyx.gpars.GParsPool.runForkJoin(GParsPool.groovy:305)
        at probleme_31$_getMatchingCombos_closure1.doCall(probleme_31.groovy:18)
        at groovyx.gpars.GParsPool$_withExistingPool_closure1.doCall(GParsPool.groovy:170)
        at groovyx.gpars.GParsPool$_withExistingPool_closure1.doCall(GParsPool.groovy)
        at groovyx.gpars.GParsPool.withExistingPool(GParsPool.groovy:169)
        at groovyx.gpars.GParsPool.withPool(GParsPool.groovy:141)
        at groovyx.gpars.GParsPool.withPool(GParsPool.groovy:117)
        at probleme_31.getMatchingCombos(probleme_31.groovy:9)
        at probleme_31.run(probleme_31.groovy:41)

I understand it has something to do with the way i want to exploit Fork/Join as a recursion “flattening” mechanism, but what is the error I’m doing here ?

  • 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-20T05:14:38+00:00Added an answer on May 20, 2026 at 5:14 am

    You’re incorrectly trying to read the children results as a return value from the forkOffChild() method, while this should be done using getChildrenResults().

            return GParsPool.runForkJoin(combos, 0, 0, target) { usableCombos, comboIndex, sum, targetSum ->
            def offset = "\t"*comboIndex
            def results = 0
            if(sum<=targetSum) {
                if(comboIndex<combos.size()) {
                    usableCombos[comboIndex].each { n ->
                        println offset+"now trying with $comboIndex element value $n (curent sum is $sum)"
                        forkOffChild(usableCombos, comboIndex+1, sum+n, targetSum)
                    }
                } else {
                    if(sum==targetSum) {
                        results +=1
                        println offset+"sum is target ! so we have $results"
                    }
                }
            }
            results += getChildrenResults().sum(0)
            return results;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My little site should be pooling list of items from a table using the
My little brother is just getting into programming, and for his Science Fair project,
We are developing a little application that given a directory with PDF files creates
Little context: We are a team of 6 developers working a web application. Since
A little context: I would like to separate the Java application I'm writing into
Skip to bottom for question, but first, a little context. So I have been
I have an interesting problem. The basis of the problem is that my last
A little while ago I managed to get Visual Studio 2008 (C++) into a
A little example TTest<T> = class private f : T; public function ToString :
A little help needed. I'm receiving an xml file similar to this: <?xml version=1.0

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.