about | help | code help+videos | done | prefs |
Write a function that takes an integer n as a parameter, and returns an n × n grid (list of lists) in which all cells on and below the main diagonal contain a 1 and the rest of the cells contain a 0. For example, if n = 5, your function should return the grid [[1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 0, 0], [1, 1, 1, 1, 0], [1, 1, 1, 1, 1]] diagonal2(3) → [[1, 0, 0], [1, 1, 0], [1, 1, 1]] diagonal2(2) → [[1, 0], [1, 1]] diagonal2(5) → [[1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 0, 0], [1, 1, 1, 1, 0], [1, 1, 1, 1, 1]] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Copyright Nick Parlante 2017 - privacy