this post was submitted on 23 Jun 2023
9 points (100.0% liked)
Code Golf
172 readers
1 users here now
Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Python - 94 chars
I tried using some alternatives, but they all ended up more verbose than:
The list tools in python are great, but they all use keywords, so doing anything that doesn't directly do for and print is likely too much. You could make a list of strings for instance, and print it all out at once to save a 'print' but you'd end up using a for in list comprehension or a join or something, so you can't really save any characters afaict.
I'm sure someone will find a way to beat it tho!
Just for fun I asked ChatGPT and got a Python in 65 chars:
Since I'm most familiar with JavaScript I'll try that myself now
Poor ChatGPT, it's always so close but so far. This doesn't meet spec :)
It doesn't print the bottom row of ' | | ', and it misses the leading spaces.
Fixing it produces:
Which is 102 characters, so longer than before. Like I said, I tried the list comp route. You get rid of some stuff, but you add more unfortunately.
However, both me and ChatGPT made the mistake of printing spaces after, which tbh isn't necessary. That can give a bit of a boost:
Which is 90, but applying it to my og answer:
Yields 82.
Putting the loop on one line saves a couple characters though:
Gets it to 80
Oh I totally missed that the trunk was part of the spec, gotta fix my own answer too