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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:42:34+00:00 2026-06-07T11:42:34+00:00

See: http://projecteuler.net/problem=18 for a better explanation of the problem than I could give here.

  • 0

See: http://projecteuler.net/problem=18 for a better explanation of the problem than I could give here.

I like my algorithm; It’s not brute-force. I look at all of the 3×3 triangles at the bottom of the pyramid to calculate which route is best, then assign that value back to the row. That’s why my function is called ConsolidateBottomThreeRows — I’ll end up calculating the best path from the bottom up, assigning to the top-most of the bottom 3 rows each time, creating a smaller and smaller pyramid until my top row contains the answer.

My issue isn’t a question of algorithm, simply syntax. I can’t figure out [yes, even with Googling] how to get my arrays passed correctly. Here is my output when I try to compile:

C:\MyApps\Euler>g++ Prob_18.cpp -o Prob_18
Prob_18.cpp: In function 'void ConsolidateBottomThreeRows(int*, int*, int*)':
Prob_18.cpp:17:20: error: request for member 'size' in 'top', which is of non-class type 'int*'

And my code:

#include <iostream>
using namespace std;

int CrunchSmallTriangle(int top[], int middle[], int bottom[])
{
    int biggest=0;
    if(middle[0]+bottom[0] > biggest) biggest=middle[0]+bottom[0];
    if(middle[0]+bottom[1] > biggest) biggest=middle[0]+bottom[1];
    if(middle[1]+bottom[0] > biggest) biggest=middle[1]+bottom[0];
    if(middle[1]+bottom[1] > biggest) biggest=middle[1]+bottom[1];
    return biggest+top[0];
}

void ConsolidateBottomThreeRows(int top[], int middle[], int bottom[])
{
    int SmallTop[0], SmallMiddle[2], SmallBottom[3];
    for(int x=0;x<top.size();x++)
    {
        SmallTop[0]=top[x];
        SmallMiddle[0]=middle[x];
        SmallMiddle[1]=middle[x+1];
        SmallBottom[0]=bottom[x];
        SmallBottom[1]=bottom[x+1];
        SmallBottom[2]=bottom[x+2];
        top[x]=CrunchSmallTriangle(SmallTop, SmallMiddle, SmallBottom);
    }
}

int main()
{
    int row1[1]={75};
    int row2[2]={95,64};
    int row3[3]={17,47,82};
    int row4[4]={18,35,87,10};
    int row5[5]={20,4,82,47,65};
    int row6[6]={19,1,23,75,3,34};
    int row7[7]={88,2,77,73,7,63,67};
    int row8[8]={99,65,4,28,6,16,70,92};
    int row9[9]={41,41,26,56,83,40,80,70,33};
    int row10[10]={41,48,72,33,47,32,37,16,94,29};
    int row11[11]={53,71,44,65,25,43,91,52,97,51,14};
    int row12[12]={70,11,33,28,77,73,17,78,39,68,17,57};
    int row13[13]={91,71,52,38,17,14,91,43,58,50,27,29,48};
    int row14[14]={63,66,4,68,89,53,67,30,73,16,69,87,40,31};
    int row15[15]={4,62,98,27,23,9,70,98,73,93,38,53,60,4,23};

    ConsolidateBottomThreeRows(row13, row14, row15);
    ConsolidateBottomThreeRows(row11, row12, row13);
    ConsolidateBottomThreeRows(row9, row10, row11);
    ConsolidateBottomThreeRows(row7, row8, row9);
    ConsolidateBottomThreeRows(row5, row6, row7);
    ConsolidateBottomThreeRows(row3, row4, row5);
    ConsolidateBottomThreeRows(row1, row2, row3);

    cout<<row1[0];
}

Any help is greatly appreciated. Thanks!

  • 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-07T11:42:35+00:00Added an answer on June 7, 2026 at 11:42 am

    Firstly, I agree with the other answers that switching from raw C-arrays to std::array<> or std::vector<> would be the best move. However, that being said, as chris commented, because your C-arrays are statically sized, making ConsolidateBottomThreeRows into a function template makes the following possible as well:

    template<std::size_t TopN, std::size_t MidN, std::size_t BotN>
    void ConsolidateBottomThreeRows(int (&top)[TopN],
                                    int (&middle)[MidN],
                                    int (&bottom)[BotN])
    {
        int SmallTop[1], SmallMiddle[2], SmallBottom[3];
        for (std::size_t x = 0; x != TopN; ++x)
        {
            SmallTop[0] = top[x];
            SmallMiddle[0] = middle[x];
            SmallMiddle[1] = middle[x + 1];
            SmallBottom[0] = bottom[x];
            SmallBottom[1] = bottom[x + 1];
            SmallBottom[2] = bottom[x + 2];
            top[x] = CrunchSmallTriangle(SmallTop, SmallMiddle, SmallBottom);
        }
    }
    

    Note that your declaration of SmallTop has the wrong dimensions.

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

Sidebar

Related Questions

I have the following fiddle for people to see http://jsfiddle.net/defaye/DhaHP/4/ The result on full
I'm wondering how to prevent Session fixation attacks in ASP.NET (see http://en.wikipedia.org/wiki/Session_fixation ) My
I've got a toggle menu, please see http://jsfiddle.net/Wp2em/41/ for code and functions. On the
UPDATE : GWT 2.3 introduces a better mechanism to fight XSRF attacks. See http://code.google.com/webtoolkit/doc/latest/DevGuideSecurityRpcXsrf.html
See http://jsfiddle.net/tAfkU/ When I'm looping through an array, how can I refer to the
See http://jsfiddle.net/FDhQF/1/ for a trivial example. What's the difference between something being undefined and
Please see: http://jasondaydesign.com/masonry_demo/ and click on the movemaine.com image I would like my transitions
Beginner here See - http://www.w3schools.com/js/tryit.asp?filename=try_dom_tablerow_cells In this example, when change content is pressed, new
Please see http://jsfiddle.net/jaWjB/1/ The line break happens in between the second image and its
I use Factories (see http://www.php.net/manual/en/language.oop5.patterns.php for the pattern) a lot to increase the testability

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.