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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:42:33+00:00 2026-06-18T22:42:33+00:00

Disclaimer: This is not a homework problem. I stumbled upon this puzzle here and

  • 0

Disclaimer: This is not a homework problem. I stumbled upon this puzzle here and I also have the answer. However, I am not able to figure out an approach to arrive at the solution.

The puzzle is as given below:

The product of the ages of David’s children is the square of the sum of their ages. David has less than eight children. None of his children have the same age. None of his children is more than 14 years old. All of his children is at least two years old. How many children does David have, and what are their ages?

The answer happens to be 2,4,6,12.

Please suggest a way to solve this problem programmatically.

  • 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-06-18T22:42:34+00:00Added an answer on June 18, 2026 at 10:42 pm

    I solved it in java using a recursive approach.
    First the program prints all the combinations, then gives the correct combination (that matches the specified criteria) at last.

    This program instantly gives the output

    (2, 4, 6, 12)
    

    just as you have specified in your question.

    public class Tackle {
    static int[] ages = {2,3,4,5,6,7,8,9,10,11,12,13,14};   // Since the program uses a recursive function,
    static StringBuffer sb = new StringBuffer("");          // the variables are declared as static
    static int x=0,occurances=0;
    static int sum,pdt=1,count=0;
    static String[] instances = new String[100];
    static void recurse(int a[], int k, int n) throws Exception
    {
        if(k==n)    // This program obtains various combinations using binary technique
        {
            for(int i=0;i<n;i++)
                if(a[i] == 1){
                        System.out.print(ages[i]+" ");   // Displays all the combinations available             
                        sum = sum + ages[i];
                        pdt = pdt * ages[i];  
                        count++;                                        
                        sb.append(String.valueOf(ages[i]+" "));
                        }
                        if(Math.pow(sum, 2) == pdt && count<8){     // Checking the criteria
                            instances[occurances++] = sb.toString();
                        }
    
                        sb = new StringBuffer("");
                        count = 0;
                        sum = 0;
                        pdt = 1;
                        System.out.println("");
        }
        else for(int i=0;i<=1;i++)
        {       
            a[x++] = i;
            recurse(a,k+1,n);
            x--;
        }
    }
    
    public static void main(String[] args) throws Exception {
        int[] a = new int[10000];
        recurse(a,0,ages.length);
        if(occurances>0)
        {
            System.out.println("No of combinations matching: " + occurances);
            for(int i=0;i<occurances;i++)
            System.out.println("The combination of ages is [ " + instances[i] + "]");
        }
        else
            System.out.println("No combination matches the criteria. ");
    }
    }
    

    The output obtained was

    [All possible combinations are listed here]
    No of combinations matching: 1
    The combination of ages is [ 2 4 6 12 ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: this question may not have practical value, it's more of a puzzle/curiosity question.
Disclaimer: This is not homework. Also, I'm describing a simplified situation so bear with
Disclaimer: This is for a programming class, but it is not the answer or
Full disclaimer: this is not really a homework, but I tagged it as such
( Disclaimer: This question is not specific to ASP.NET) I have a control which
DISCLAIMER: This question is related to homework. I am not expecting a solution, but
Disclaimer: This is homework. I am attempting it and do not expect or want
Disclaimer: I apologize if this is not an appropriate question to ask here... I
Disclaimer: This is for a homework assignment, but the question is not regarding the
Disclaimer: this question is purely informational and does not represent an actual problem I'm

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.