Skip to main content
added 207 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293
R«Ṛ$‘r⁸ṬUÐeYR«Ṛ$‘r⁸ṬUÐe0YE? 

A full program accepting an integer which prints the output as defined in the OP using 0 and 1 for * and # respectively.

R«Ṛ$‘r⁸ṬUÐeYR«Ṛ$‘r⁸ṬUÐe0YE? - Main Link: integer, n R  - range -> [1,2,3,4,...,n] $  - last two links as a monad: Ṛ  - reverse -> [n,...,4,3,2,1] «  - minimum (vectorises) -> [1,2,3,4,...,4,3,2,1] ‘  - increment (vectorises) -> [2,3,4,5,...,5,4,3,2] ⁸  - chain's left argument, n r  - inclusive range (vectorises) -> [[2,3,...,n],[3,4,...n],[4,5,...n],[5,...n],...,[5,...n],[4,5,...n],[3,4,...n],[2,3,...,n]] Ṭ  - untruth (vectorises) -> [[0,1,1,...,1],[0,0,1,1,...,1],[0,0,0,1,...,1],[0,0,0,0,1,...,1],...,[0,0,0,0,1,...,1],[0,0,0,1,...,1],[0,0,1,1,...,1],[0,1,1,...,1]] Ðe  - apply to entries with even indices: U  - upend -> [[0,1,1,...,1],[1,1,...,1],[0,0,0,1,...,1],[1,...,1,0,0,0,0],...] ? - if... E - ...condition: all equal? (only true when n=1, where we have [1,1]) 0 - ...then: zero   Y  - ...else: join with newline characters   - implicit print 
R«Ṛ$‘r⁸ṬUÐeY 

A full program accepting an integer which prints the output as defined in the OP.

R«Ṛ$‘r⁸ṬUÐeY - Main Link: integer, n R - range -> [1,2,3,4,...,n] $ - last two links as a monad: Ṛ - reverse -> [n,...,4,3,2,1] « - minimum (vectorises) -> [1,2,3,4,...,4,3,2,1] ‘ - increment (vectorises) -> [2,3,4,5,...,5,4,3,2] ⁸ - chain's left argument, n r - inclusive range (vectorises) -> [[2,3,...,n],[3,4,...n],[4,5,...n],[5,...n],...,[5,...n],[4,5,...n],[3,4,...n],[2,3,...,n]] Ṭ - untruth (vectorises) -> [[0,1,1,...,1],[0,0,1,1,...,1],[0,0,0,1,...,1],[0,0,0,0,1,...,1],...,[0,0,0,0,1,...,1],[0,0,0,1,...,1],[0,0,1,1,...,1],[0,1,1,...,1]] Ðe - apply to entries with even indices: U - upend -> [[0,1,1,...,1],[1,1,...,1],[0,0,0,1,...,1],[1,...,1,0,0,0,0],...] Y - join with newline characters - implicit print 
R«Ṛ$‘r⁸ṬUÐe0YE? 

A full program accepting an integer which prints the output as defined in the OP using 0 and 1 for * and # respectively.

R«Ṛ$‘r⁸ṬUÐe0YE? - Main Link: integer, n R  - range -> [1,2,3,4,...,n] $  - last two links as a monad: Ṛ  - reverse -> [n,...,4,3,2,1] «  - minimum (vectorises) -> [1,2,3,4,...,4,3,2,1] ‘  - increment (vectorises) -> [2,3,4,5,...,5,4,3,2] ⁸  - chain's left argument, n r  - inclusive range (vectorises) -> [[2,3,...,n],[3,4,...n],[4,5,...n],[5,...n],...,[5,...n],[4,5,...n],[3,4,...n],[2,3,...,n]] Ṭ  - untruth (vectorises) -> [[0,1,1,...,1],[0,0,1,1,...,1],[0,0,0,1,...,1],[0,0,0,0,1,...,1],...,[0,0,0,0,1,...,1],[0,0,0,1,...,1],[0,0,1,1,...,1],[0,1,1,...,1]] Ðe  - apply to entries with even indices: U  - upend -> [[0,1,1,...,1],[1,1,...,1],[0,0,0,1,...,1],[1,...,1,0,0,0,0],...] ? - if... E - ...condition: all equal? (only true when n=1, where we have [1,1]) 0 - ...then: zero   Y  - ...else: join with newline characters   - implicit print 
Post Undeleted by Jonathan Allan
deleted 19 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

Jelly, 12 12  15 bytes

+3 fixing n=1 edge-case bug :(

R«Ṛ$‘r⁸ṬUÐeY 

A monadic linkfull program accepting an integer which yields a mixed-list of integers and newline characters. When run as a full program this is printedprints the output as defined in the OP.

Try it online!Try it online!

How?

R«Ṛ$‘r⁸ṬUÐeY - Main Link: integer, n R - range -> [1,2,3,4,...,n] $ - last two links as a monad: Ṛ - reverse -> [n,...,4,3,2,1] « - minimum (vectorises) -> [1,2,3,4,...,4,3,2,1] ‘ - increment (vectorises) -> [2,3,4,5,...,5,4,3,2] ⁸ - chain's left argument, n r - inclusive range (vectorises) -> [[2,3,...,n],[3,4,...n],[4,5,...n],[5,...n],...,[5,...n],[4,5,...n],[3,4,...n],[2,3,...,n]] Ṭ - untruth (vectorises) -> [[0,1,1,...,1],[0,0,1,1,...,1],[0,0,0,1,...,1],[0,0,0,0,1,...,1],...,[0,0,0,0,1,...,1],[0,0,0,1,...,1],[0,0,1,1,...,1],[0,1,1,...,1]] Ðe - apply to entries with even indices: U - upend -> [[0,1,1,...,1],[1,1,...,1],[0,0,0,1,...,1],[1,...,1,0,0,0,0],...] Y - join with newline characters - implicit print 

Jelly, 12 bytes

R«Ṛ$‘r⁸ṬUÐeY 

A monadic link accepting an integer which yields a mixed-list of integers and newline characters. When run as a full program this is printed as defined in the OP.

Try it online!

How?

R«Ṛ$‘r⁸ṬUÐeY - Main Link: integer, n R - range -> [1,2,3,4,...,n] $ - last two links as a monad: Ṛ - reverse -> [n,...,4,3,2,1] « - minimum (vectorises) -> [1,2,3,4,...,4,3,2,1] ‘ - increment (vectorises) -> [2,3,4,5,...,5,4,3,2] ⁸ - chain's left argument, n r - inclusive range (vectorises) -> [[2,3,...,n],[3,4,...n],[4,5,...n],[5,...n],...,[5,...n],[4,5,...n],[3,4,...n],[2,3,...,n]] Ṭ - untruth (vectorises) -> [[0,1,1,...,1],[0,0,1,1,...,1],[0,0,0,1,...,1],[0,0,0,0,1,...,1],...,[0,0,0,0,1,...,1],[0,0,0,1,...,1],[0,0,1,1,...,1],[0,1,1,...,1]] Ðe - apply to entries with even indices: U - upend -> [[0,1,1,...,1],[1,1,...,1],[0,0,0,1,...,1],[1,...,1,0,0,0,0],...] Y - join with newline characters - implicit print 

Jelly,  12  15 bytes

+3 fixing n=1 edge-case bug :(

R«Ṛ$‘r⁸ṬUÐeY 

A full program accepting an integer which prints the output as defined in the OP.

Try it online!

How?

R«Ṛ$‘r⁸ṬUÐeY - Main Link: integer, n R - range -> [1,2,3,4,...,n] $ - last two links as a monad: Ṛ - reverse -> [n,...,4,3,2,1] « - minimum (vectorises) -> [1,2,3,4,...,4,3,2,1] ‘ - increment (vectorises) -> [2,3,4,5,...,5,4,3,2] ⁸ - chain's left argument, n r - inclusive range (vectorises) -> [[2,3,...,n],[3,4,...n],[4,5,...n],[5,...n],...,[5,...n],[4,5,...n],[3,4,...n],[2,3,...,n]] Ṭ - untruth (vectorises) -> [[0,1,1,...,1],[0,0,1,1,...,1],[0,0,0,1,...,1],[0,0,0,0,1,...,1],...,[0,0,0,0,1,...,1],[0,0,0,1,...,1],[0,0,1,1,...,1],[0,1,1,...,1]] Ðe - apply to entries with even indices: U - upend -> [[0,1,1,...,1],[1,1,...,1],[0,0,0,1,...,1],[1,...,1,0,0,0,0],...] Y - join with newline characters - implicit print 
Post Deleted by Jonathan Allan
added 952 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

Jelly, 12 bytes

R«Ṛ$‘r⁸ṬUÐeY 

A monadic link accepting an integer which yields a mixed-list of integers and newline characters. When run as a full program this is printed as defined in the OP.

Try it online!

How?

R«Ṛ$‘r⁸ṬUÐeY - Main Link: integer, n R - range -> [1,2,3,4,...,n] $ - last two links as a monad: Ṛ - reverse -> [n,...,4,3,2,1] « - minimum (vectorises) -> [1,2,3,4,...,4,3,2,1] ‘ - increment (vectorises) -> [2,3,4,5,...,5,4,3,2] ⁸ - chain's left argument, n r - inclusive range (vectorises) -> [[2,3,...,n],[3,4,...n],[4,5,...n],[5,...n],...,[5,...n],[4,5,...n],[3,4,...n],[2,3,...,n]] Ṭ - untruth (vectorises) -> [[0,1,1,...,1],[0,0,1,1,...,1],[0,0,0,1,...,1],[0,0,0,0,1,...,1],...,[0,0,0,0,1,...,1],[0,0,0,1,...,1],[0,0,1,1,...,1],[0,1,1,...,1]] Ðe - apply to entries with even indices: U - upend -> [[0,1,1,...,1],[1,1,...,1],[0,0,0,1,...,1],[1,...,1,0,0,0,0],...] Y - join with newline characters - implicit print 

Jelly, 12 bytes

R«Ṛ$‘r⁸ṬUÐeY 

A monadic link accepting an integer which yields a mixed-list of integers and newline characters. When run as a full program this is printed as defined in the OP.

Try it online!

Jelly, 12 bytes

R«Ṛ$‘r⁸ṬUÐeY 

A monadic link accepting an integer which yields a mixed-list of integers and newline characters. When run as a full program this is printed as defined in the OP.

Try it online!

How?

R«Ṛ$‘r⁸ṬUÐeY - Main Link: integer, n R - range -> [1,2,3,4,...,n] $ - last two links as a monad: Ṛ - reverse -> [n,...,4,3,2,1] « - minimum (vectorises) -> [1,2,3,4,...,4,3,2,1] ‘ - increment (vectorises) -> [2,3,4,5,...,5,4,3,2] ⁸ - chain's left argument, n r - inclusive range (vectorises) -> [[2,3,...,n],[3,4,...n],[4,5,...n],[5,...n],...,[5,...n],[4,5,...n],[3,4,...n],[2,3,...,n]] Ṭ - untruth (vectorises) -> [[0,1,1,...,1],[0,0,1,1,...,1],[0,0,0,1,...,1],[0,0,0,0,1,...,1],...,[0,0,0,0,1,...,1],[0,0,0,1,...,1],[0,0,1,1,...,1],[0,1,1,...,1]] Ðe - apply to entries with even indices: U - upend -> [[0,1,1,...,1],[1,1,...,1],[0,0,0,1,...,1],[1,...,1,0,0,0,0],...] Y - join with newline characters - implicit print 
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293
Loading