Problem 432104 · easy · Phase 04 Non-Linear Data Structures

Lamp Row Encoding

recursion · binary · integer division

A stage has a row of lamps, and a lighting cue is stored as a non-negative integer n. Lamp i from the right is on when bit i of n is 1. Write lamp_code(n) returning the binary representation of n as a string of '0' and '1' characters with no leading zeros, built recursively (do not use bin, format, or f-string conversions).

Examples

Input:  n = 10
Output: "1010"

Input:  n = 0
Output: "0"

Constraints

  • 0 <= n < 2**64, so at most 64 recursive levels.

Goals

  • Peel off the lowest binary digit with % and //
  • Order the recursive result and the current digit correctly
  • Handle 0 and 1 as base cases
Starting Python…