just notes

Using list comprehension to find combinations of cube dimensions that don’t add up to `n`


Input (stdin)

  • 1
  • 1
  • 1
  • 2

Expected Output

  • [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
if __name__ == '__main__':
    x = int(input())
    y = int(input())
    z = int(input())
    n = int(input())
    
    result = sorted(
            [ [i,j,k] for k in range(0,z+1) 
            for j in range(0,y + 1) 
            for i in range(0,x + 1) 
            if (i + j + k) != n ]
        )

    print(result)

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.