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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:27:09+00:00 2026-06-11T04:27:09+00:00

Project Euler problem 18 asks us to find the route from top to bottom

  • 0

Project Euler problem 18 asks us to find the route from top to bottom of a triangular grid with the maximum sum.

My program should be able to take in input as shown below. The number of test cases (2) appears on the first line, and then for each test case the number of rows is given (4) and then the data for the test case, one row per line.

2 
4 
3 
7 4
2 4 6
8 5 9 3
6
690
650 901
65 774 67
435 248 677 385
878 90 378 191 703
141 296 143 756 938 529

The program should produce one line of output for each test case, giving the route with the maximum sum:

23 
4176

I have tried to implement it using python.

The code is below:

def triangle(rows):
    PrintingList = list()
    for rownum in range (rows ):     
        PrintingList.append([])
        newValues = raw_input().strip().split()
        PrintingList[rownum] += newValues
    return PrintingList

def routes(rows,current_row=0,start=0): 
        for i,num in enumerate(rows[current_row]): 
            if abs(i-start) > 1:   
                continue
            if current_row == len(rows) - 1: 
                yield [num]
            else:
                for child in routes(rows,current_row+1,i):
                    yield [num] + child

testcases = int(raw_input())
for num in range(testcases):
    rows= int(raw_input())
    triangleinput = triangle(rows)
    max_route = max(routes(triangleinput),key=sum)
    sum(max_route)

When i type this:

1
3
1
2 3
4 5 6

I get this error:

Traceback (most recent call last):
  File "Maximum Route.py", line 23, in <module>
    max_route = max(routes(triangleinput),key=sum)
TypeError: unsupported operand type(s) for +: 'int' and 'str'

Need some guidance.. Do point out if there are other errors… 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-11T04:27:11+00:00Added an answer on June 11, 2026 at 4:27 am

    Here’s the problem:

    newValues = raw_input().strip().split()
    

    You need to convert your input to integers:

    newValues = map(int, raw_input().split())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Project Euler, a problem asks me to write a program to find the
I'm trying to solving Project Euler Problem 14 . It asks to find the
I'm doing problem 20 on Project Euler - finding the sum of the digits
This is from project Euler, problem 2. I wrote the following seemingly innocent code:
The 10th problem in Project Euler: The sum of the primes below 10 is
I am working on Project Euler Problem 4 , and need to find the
I was trying to solve Project Euler problem 10 using python, but my program
This is problem 11 on Project Euler. It gives a 20x20 grid of numbers
I am doing another Project Euler problem and I need to find when the
I have a linq query for project euler problem 243: var y = from

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.