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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:19:03+00:00 2026-05-11T01:19:03+00:00

I am trying to resolve Euler Problem 18 -> http://projecteuler.net/index.php?section=problems&id=18 I am trying to

  • 0

I am trying to resolve Euler Problem 18 -> http://projecteuler.net/index.php?section=problems&id=18

I am trying to do this with c++ (I am relearning it and euler problems make for good learning/searching material)

#include <iostream>  using namespace std;  long long unsigned countNums(short,short,short array[][15],short,bool,bool);  int main(int argc,char **argv) {      long long unsigned max = 0;     long long unsigned sum;       short piramide[][15] = {{75,0,0,0,0,0,0,0,0,0,0,0,0,0,0},                             {95,64,0,0,0,0,0,0,0,0,0,0,0,0,0},                             {17,47,82,0,0,0,0,0,0,0,0,0,0,0,0},                             {18,35,87,10,0,0,0,0,0,0,0,0,0,0,0},                             {20,4,82,47,65,0,0,0,0,0,0,0,0,0,0},                             {19,1,23,75,3,34,0,0,0,0,0,0,0,0,0},                             {88,2,77,73,7,63,67,0,0,0,0,0,0,0,0},                             {99,65,4 ,28,6,16,70,92,0,0,0,0,0,0,0},                             {41,41,26,56,83,40,80,70,33,0,0,0,0,0,0},                             {41,48,72,33,47,32,37,16,94,29,0,0,0,0,0},                             {53,71,44,65,25,43,91,52,97,51,14,0,0,0,0},                             {70,11,33,28,77,73,17,78,39,68,17,57,0,0,0},                             {91,71,52,38,17,14,91,43,58,50,27,29,48,0,0},                             {63,66,4,68,89,53,67,30,73,16,69,87,40,31,0},                             {4,62,98,27,23,9,70,98,73,93,38,53,60,4,23}};      for (short i = 0;i<15;i++) {         for (short m=0;m<15;m++) {             if (piramide[i][m] == 0)                 break;             sum = countNums(i,m,piramide,15,true,true);             if (sum > max)                 max = sum;             sum = countNums(i,m,piramide,15,true,false);             if (sum > max)                 max = sum;             sum = countNums(i,m,piramide,15,false,true);             if (sum > max)                 max = sum;             sum = countNums(i,m,piramide,15,false,false);             if (sum > max)                max = sum;          }      }     cout << max;     return 0; }   long long unsigned countNums(short start_x,short start_y,short array[][15],short size, bool goright,bool goright2) {     long long unsigned currentSum;      currentSum = array[start_x][start_y];      if (goright) { //go right         if ((start_x + 1) < size)             start_x++;         if ((start_y + 1) < size)             start_y++;     }     else //go down         if ((start_x + 1) < size)             start_x++;      if (goright2) { //still going right         for (short i = start_x, m = start_y;i< size && m < size;i++,m++) {             currentSum += array[i][m];                  }     }     else { //still going down         for (short i = start_x;i<size;i++) {             currentSum += array[i][start_y];                     }     }      return currentSum; } 

The countNums function is used to go either down or diagonally. I have tested this function like so:

short a = 0; short b = 0; cout << countNums(a,b,piramide,15,true,true) << endl; cout << countNums(a,b,piramide,15,true,false) << endl; cout << countNums(a,b,piramide,15,false,true) << endl; cout << countNums(a,b,piramide,15,false,false) << endl; return 0; 

And it does work (I also changed the function a little so it would print every number it was going through)

But I still don’t get the right result. This goes down and to the right and still goes right (adjacent numbers to the right), goes down and keeps going down (adjacent number to the left). What am I doing wrong here, anyone?


Alastair: It’s simple

long long unsigned countNums(short start_x,short start_y,short array[][15],short size, bool goright,bool goright2);

start_x and start_y are the coords of the array array is the reference to the array size is just the size of the array (it’s always 15) goright is to know if I am going to go down and right or just down goright2 is to know if I am going to continue to go down or going left

  • 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. 2026-05-11T01:19:03+00:00Added an answer on May 11, 2026 at 1:19 am

    Ok so first off, I’m a little unclear as to what you think the problem is. I can’t parse that second-last sentence at all…

    Secondly you might want to re-think your design here. Think about functions that perform a single discrete task and are not intertwined with the rest of the application (ie read up on ‘tightly coupled and loosely bound’). For me a big warning bell here is the presence of a overly-generic function name countNums with a long list of arguments.

    I think if you were to divide the problem into smaller, more easily comprehensible, chunks you might find the problems a lot easier to find. I know the approach that I would take here but I’m assuming the whole point of the exercise is to help you practice your programming skills, so I’ll just leave it at that…

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

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Close, but catching an IOException won't work because that exception… May 11, 2026 at 3:33 pm
  • added an answer There is a huge performance penalty to using ENUM for… May 11, 2026 at 3:32 pm
  • added an answer Using the app delegate to store data that's shared between… May 11, 2026 at 3:32 pm

Related Questions

I am trying to resolve Euler Problem 18 -> http://projecteuler.net/index.php?section=problems&id=18 I am trying to
I am trying to develop a .NET Web Project using NHibernate and Spring.NET, but
I am trying to write a function to determine if a file exists. The
I am trying to create unittests that can be shared amongst my development team
I am trying to use Validation in WPF. I created a NotNullOrEmptyValidationRule as shown

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.