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

  • Home
  • SEARCH
  • 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 6877435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:36:01+00:00 2026-05-27T04:36:01+00:00

So the problem I’m working on solving involves an array list of array list

  • 0

So the problem I’m working on solving involves an array list of array list of integers
. What is known: The number of elements in each ArrayList of integers. What is NOT known: How many ArrayList of Integers there actually are. I need suggestions for an algorithm that would sum the (ordered) elements of these arrays in every combination possible OF the arrays. In order to clarify what I mean by this let me give an example:

AoA = [[1,0,1,0],[0,1,0,1],[1,1,1,1],[0,0,0,0]];

Sum the elements of AoA[0] + AoA[1]; AoA[0]+AoA[2]; AoA[0]+AoA[3]; AoA[1]+AoA[2]; AoA[1]+AoA[3]; AoA[2]+AoA[3];

(4 choose 2)

So if anyone could code this simple version I’d be grateful as I’m struggling to do it. If anyone could code the more complex example where there’s an unknown number of arrays in the AoA (so N choose 2), you’d be my hero.

TL;DR/edit

I need an algorithm to take n-choose-2 arrays from an array of arrays; sum the arrays (e.g. [1,2,3] + [1,2,3] = [2,4,6]); put the add the new summed array into an array of arrays.

  • 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-27T04:36:02+00:00Added an answer on May 27, 2026 at 4:36 am

    Here’s what I’ve got, took me a while but this will do what I was looking for:
    it takes each combination of the arrays (t1, t2, t3, t4) and adds their elements and returns whatever combinatorial you choose for n, (in this example i left it as 3).

    If there’s any more optimizations you can see please feel free to add it. I’m a perl guy so making this work at all in Java was a real task.

    import java.util.ArrayList;
    
    
    public class testnCk {
    
        public static void main(String[] args) {
    
            ArrayList<int[]> sums = new ArrayList<int[]>();
            int [] t1 = {1,1,0,0};
            int [] t2 = {1,0,0,1};
            int [] t3 = {0,0,0,0};
            int [] t4 = {0,0,1,1};
            ArrayList<int[]> testing = new ArrayList<int[]>();
            testing.add(t1);
            testing.add(t2);
            testing.add(t3);
            testing.add(t4);
    
            int n = 3;
            int i = -1;
            int[] array = new int[4];
            ArrayList<int[]> whatever = nCk(testing, sums, array, i, n);
    
            for (int[] test1 : whatever)
            {
                for (int j = 0; j < test1.length; j++) {
                    System.out.print(test1[j]);
                }
                System.out.println();
            }
        }
        public static ArrayList<int[]> nCk (ArrayList<int[]> arrayOfDiffPatterns, ArrayList<int[]> solutions, int[] tempsums, int i, int n)
        {
            n--;
            for (int j=i+1; j<arrayOfDiffPatterns.size(); j++){
                int[] array = tempsums.clone();
                for (int k=0; k<arrayOfDiffPatterns.get(0).length; k++){
                        array[k] += arrayOfDiffPatterns.get(j)[k];
                }
                if(n>0){
                    nCk(arrayOfDiffPatterns, solutions, array, j, n);
                }
                else{
                    solutions.add(array);
                }
            }
            return solutions;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem: Given a list of strings, find the substring which, if subtracted from the
Problem: I can set the exposureMode property of AVCaptureDevice, but it does not stay
Problem: I'm working on a website where there is a dial that displays a
Problem: I need an array (datamember) in a parent class A. However, depending on
Problem, simple and annoying. Im just trying to print a list of names, collected
Problem: I don't know why my script is not loading a value into the
Problem: When adding list item the Value field is being set to the Text
PROBLEM SOLVED. Special thanks to Andrew Noyes for explaining its not a class but
Problem: I have a large database table (~500k records) which has a list of

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.