Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges My house is destroyed! Can you make me one?

Python 3, 47 42 40 bytes -2 bytes thanks to bastolski lambda n:'#'*n+('\n#'+' '*(n-2)+'#')*~-n Try it online! Python's string multiplication is really useful.

posted 3y ago by Moshi‭  ·  edited 3y ago by Moshi‭

Answer
#3: Post edited by user avatar Moshi‭ · 2021-08-28T05:11:28Z (about 3 years ago)
  • # [Python 3], ~~47~~ 42 bytes
  • ```python
  • lambda n:'#'*n+('
  • #'+' '*(n-2)+'#')*(n-1)
  • ```
  • [Try it online!][TIO-ksth5zpv]
  • Python's string multiplication is really useful.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ksth5zpv]: https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPSl1ZXStPW0M9Jk9ZXVtdQV1LI0/XSFMbKKwJYhpq/i8oyswr0UjTMNbU5IKxTZHYhgaamv8B "Python 3 – Try It Online"
  • # [Python 3], ~~47~~ ~~42~~ 40 bytes
  • *-2 bytes thanks to [bastolski](https://codegolf.codidact.com/users/54221)*
  • ```python
  • lambda n:'#'*n+('
  • #'+' '*(n-2)+'#')*~-n
  • ```
  • [Try it online!][TIO-ksth5zpv]
  • Python's string multiplication is really useful.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ksth5zpv]: https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPSl1ZXStPW0M9Jk9ZXVtdQV1LI0/XSFMbKKypVaeb97@gKDOvRCNNw1hTkwvGNkViGxpoav4HAA
#2: Post edited by user avatar Moshi‭ · 2021-08-26T22:09:01Z (about 3 years ago)
  • # [Python 3], 47 bytes
  • ```python
  • lambda n:'#'*n+'\n'+('#'+' '*(n-2)+'#\n')*(n-1)
  • ```
  • [Try it online!][TIO-ksth5zpv]
  • Python's string multiplication is really useful.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ksth5zpv]: https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPSl1ZXStPWz0mT11bA8jWVldQ19LI0zXS1FZXBgpqgjiGmv8LijLzSjTSNIw1NblgbFMktqGBpuZ/AA "Python 3 – Try It Online"
  • # [Python 3], ~~47~~ 42 bytes
  • ```python
  • lambda n:'#'*n+('\n#'+' '*(n-2)+'#')*(n-1)
  • ```
  • [Try it online!][TIO-ksth5zpv]
  • Python's string multiplication is really useful.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ksth5zpv]: https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPSl1ZXStPW0M9Jk9ZXVtdQV1LI0/XSFMbKKwJYhpq/i8oyswr0UjTMNbU5IKxTZHYhgaamv8B "Python 3 – Try It Online"
#1: Initial revision by user avatar Moshi‭ · 2021-08-26T22:06:44Z (about 3 years ago)
# [Python 3], 47 bytes

```python
lambda n:'#'*n+'\n'+('#'+' '*(n-2)+'#\n')*(n-1)
```

[Try it online!][TIO-ksth5zpv]

Python's string multiplication is really useful.

[Python 3]: https://docs.python.org/3/
[TIO-ksth5zpv]: https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPSl1ZXStPWz0mT11bA8jWVldQ19LI0zXS1FZXBgpqgjiGmv8LijLzSjTSNIw1NblgbFMktqGBpuZ/AA "Python 3 – Try It Online"