Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Output a binary path from a number

For an integer n that satisfies n > 0, write its value as a right-descending path based on its binary representation.

Rules

  • The first (most significant) set bit is always in the top-left corner.
  • When the next bit is set (a 1), draw a character ("filled") on the next line in the same column as the previous character drawn. Try to use spaces ("empty") to fill, but any character will do as long as it's always the same.
  • When the next bit is unset (a 0), draw a character ("filled") on the same line immediately to the the right of the previous character drawn.
  • Your code must support numbers with at least 20 significant bits.
  • Write a full program, a function, a lambda, etc. but no snippet.
  • No leading spaces (or "empty" char) / lines allowed
  • Any number of trailing spaces (or "empty" char) / lines allowed
  • Any kind of 1D input is accepted: number, string, array of booleans, etc. Keep the order of bits untouched though.
  • Any kind of visual 2D output is accepted: on stdout, a string (with any two distinct values representing "filled" and "empty"), you can even output a matrix if you want. A list of numbers seems hard to reconcile with the "no heading spaces" rule, but I'm open to it if you find a way to use it. Note: if you chose to print or return a string, the characters used must be ASCII characters in the codepoints range [32-126].
  • Standard loopholes are banned.
  • This is codegolf so the shortest code wins.

Examples

Input: 1

*

Input: 2

**

Input: 3

*
*

Input: 4

***

Input: 5

**
 *

Input: 6

*
**

Input: 7

*
*
*

Input: 25

*
***
 *

Input: 699050

**
 **
 **
 **
 **
 **
 **
 **
 **
 **

Input: 1047552

*
*
*
*
*
*
*
*
*
***********

Input: 525311

**********
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *

Answer*

Draft saved
Draft discarded
Cancel
3
  • 1
    \$\begingroup\$ γ€gć¸s>«1IÔ·ÌΛ should save 4 bytes. \$\endgroup\$ Commented Apr 6, 2018 at 10:19
  • \$\begingroup\$ @Emigna Brilliant, thanks ! Totally forgot that there was an a+2 builtin o: \$\endgroup\$ Commented Apr 6, 2018 at 10:22
  • \$\begingroup\$ I realize these weren't possible yet when you posted your answer, but you can save 3 bytes now in the new 05AB1E version by changing γ€g to Åγ; ć¸s>« to >ć<š and 1I to $: Try it online: Åγ>ć<š$Ô·ÌΛ. \$\endgroup\$ Commented Apr 1, 2020 at 12:27

AltStyle によって変換されたページ (->オリジナル) /