1

I'm working on an question that's part of the CCC(question: https://dmoj.ca/problem/ccc18s2) I have my code, but it doesnt work all the time. When I input my code into the online grader (which can be found on the linked page) I only get 3/15 marks. All the inputs I put in myself seem to work out, but the grader seems to be different.

My code:

lowest_val = []
flower=[]

n = int(input())
for i in range(0,n):
    flower.append(input().split(" "))

lowest_val.append(flower[0][0])
lowest_val.append(flower[0][n-1])
lowest_val.append(flower[n-1][0])
lowest_val.append(flower[n-1][n-1])

while True:
    if flower[0][0] == min(lowest_val):
        for row in flower:
            for i in row:
                print(i, end=" ")
            print()
        break
    flower = list(zip(*flower[::-1]))

To answer this question, I can simply check if the top left corner is the smallest corner, so flower[0][0] must be the smallest corner.

min() looks for the smallest number out of the 4 corner that I added to the list lowest_val.

I cant find a test where this fails, and that might be my biggest problem. On dmoj (the online grader) all it does is say I got part of the question wrong.

itsanantk
  • 264
  • 1
  • 9
  • * What type is `flower[0][0]`? * What does `min()` return on a list of this type? * Can you construct a test case where this fails, or should we provide one? – cidermole Feb 21 '21 at 09:02
  • To answer this question, I can simply check if the top left corner is the smallest corner(flower[0][0] must be the smallest corner). min() looks for the smallest number out of the 4 corner that I added to the list lowest_val. I cant find a test where this fails, and that might be my biggest problem. On dmoj (the online grader) all it does is say I got part of the question wrong. – itsanantk Feb 21 '21 at 19:28

2 Answers2

1

Here is a test case that fails with your code:

2
10 4
3 2

Can you find out why it fails?

cidermole
  • 5,662
  • 1
  • 15
  • 21
  • 1
    Ohh, I added the list corners into another list, but they were strings, not integers. It checked which one was lowest alphabetically. Just fixed it by converting them to integers. – itsanantk Feb 23 '21 at 02:57
0

Figured out why my code didn't work all the time:

When I added the list corners to lowest_val the elements were all strings, not integers.

Because of that, min(lowest_val) got me the lowest value, sorted alphabetically.

To solve it I simply made all the elements integers.

itsanantk
  • 264
  • 1
  • 9