3
On CodingGame, there is a Puzzle that ask to write words with ascii art. I solve the puzzle then tried to golf it. What improvement can I do on it?
INPUT
>>> 20
>>> 11
>>> MANHATTAN
>>> .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .-----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------.
>>> | .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |
>>> | | __ | || | ______ | || | ______ | || | ________ | || | _________ | || | _________ | || | ______ | || | ____ ____ | || | _____ | || | _____ | || | ___ ____ | || | _____ | || | ____ ____ | || | ____ _____ | || | ____ | || | ______ | || | ___ | || | _______ | || | _______ | || | _________ | || | _____ _____ | || | ____ ____ | || | _____ _____ | || | ____ ____ | || | ____ ____ | || | ________ | || | ______ | |
>>> | | / \ | || | |_ _ \ | || | .' ___ | | || | |_ ___ `. | || | |_ ___ | | || | |_ ___ | | || | .' ___ | | || | |_ || _| | || | |_ _| | || | |_ _| | || | |_ ||_ _| | || | |_ _| | || ||_ \ / _|| || ||_ \|_ _| | || | .' `. | || | |_ __ \ | || | .' '. | || | |_ __ \ | || | / ___ | | || | | _ _ | | || ||_ _||_ _|| || ||_ _| |_ _| | || ||_ _||_ _|| || | |_ _||_ _| | || | |_ _||_ _| | || | | __ _| | || | / _ __ `. | |
>>> | | / /\ \ | || | | |_) | | || | / .' \_| | || | | | `. \ | || | | |_ \_| | || | | |_ \_| | || | / .' \_| | || | | |__| | | || | | | | || | | | | || | | |_/ / | || | | | | || | | \/ | | || | | \ | | | || | / .--. \ | || | | |__) | | || | / .-. \ | || | | |__) | | || | | (__ \_| | || | |_/ | | \_| | || | | | | | | || | \ \ / / | || | | | /\ | | | || | \ \ / / | || | \ \ / / | || | |_/ / / | || | |_/____) | | |
>>> | | / ____ \ | || | | __'. | || | | | | || | | | | | | || | | _| _ | || | | _| | || | | | ____ | || | | __ | | || | | | | || | _ | | | || | | __'. | || | | | _ | || | | |\ /| | | || | | |\ \| | | || | | | | | | || | | ___/ | || | | | | | | || | | __ / | || | '.___`-. | || | | | | || | | ' ' | | || | \ \ / / | || | | |/ \| | | || | > `' < | || | \ \/ / | || | .'.' _ | || | / ___.' | |
>>> | | _/ / \ \_ | || | _| |__) | | || | \ `.___.'\ | || | _| |___.' / | || | _| |___/ | | || | _| |_ | || | \ `.___] _| | || | _| | | |_ | || | _| |_ | || | | |_' | | || | _| | \ \_ | || | _| |__/ | | || | _| |_\/_| |_ | || | _| |_\ |_ | || | \ `--' / | || | _| |_ | || | \ `-' \_ | || | _| | \ \_ | || | |`\____) | | || | _| |_ | || | \ `--' / | || | \ ' / | || | | /\ | | || | _/ /'`\ \_ | || | _| |_ | || | _/ /__/ | | || | |_| | |
>>> | ||____| |____|| || | |_______/ | || | `._____.' | || | |________.' | || | |_________| | || | |_____| | || | `._____.' | || | |____||____| | || | |_____| | || | `.___.' | || | |____||____| | || | |________| | || ||_____||_____|| || ||_____|\____| | || | `.____.' | || | |_____| | || | `.___.\__| | || | |____| |___| | || | |_______.' | || | |_____| | || | `.__.' | || | \_/ | || | |__/ \__| | || | |____||____| | || | |______| | || | |________| | || | (_) | |
>>> | | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | |
>>> | '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |
>>> '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------'
OUPUT:
.----------------. .----------------. .-----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .-----------------.
| .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |
| | ____ ____ | || | __ | || | ____ _____ | || | ____ ____ | || | __ | || | _________ | || | _________ | || | __ | || | ____ _____ | |
| ||_ \ / _|| || | / \ | || ||_ \|_ _| | || | |_ || _| | || | / \ | || | | _ _ | | || | | _ _ | | || | / \ | || ||_ \|_ _| | |
| | | \/ | | || | / /\ \ | || | | \ | | | || | | |__| | | || | / /\ \ | || | |_/ | | \_| | || | |_/ | | \_| | || | / /\ \ | || | | \ | | | |
| | | |\ /| | | || | / ____ \ | || | | |\ \| | | || | | __ | | || | / ____ \ | || | | | | || | | | | || | / ____ \ | || | | |\ \| | | |
| | _| |_\/_| |_ | || | _/ / \ \_ | || | _| |_\ |_ | || | _| | | |_ | || | _/ / \ \_ | || | _| |_ | || | _| |_ | || | _/ / \ \_ | || | _| |_\ |_ | |
| ||_____||_____|| || ||____| |____|| || ||_____|\____| | || | |____||____| | || ||____| |____|| || | |_____| | || | |_____| | || ||____| |____|| || ||_____|\____| | |
| | | || | | || | | || | | || | | || | | || | | || | | || | | |
| '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |
'----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------'
Python 3: 145 bytes
i=input;l=int(i());h=int(i());t=[ord(c)-65if c.isalpha()else 26for c in i().upper()]
while h:h-=1;r=i();print(''.join(r[j*l:l*(j+1)] for j in t))
2
(j+1)
can be-~j
. The space between]
andfor
can be omitted. – Arnauld – 2019-12-23T17:27:54.3971
c.isalpha()*(ord(c)-91)+26
is shorter than theif
. – manatwork – 2019-12-23T18:35:33.533Is
?
the only non-alphabetic character? – Jonathan Allan – 2019-12-23T18:38:44.2971@JonathanAllan, that seems to be the joker to replace any non-alphabetic character, like in
tr --complement 'A-Z' '?'
. – manatwork – 2019-12-23T18:40:02.270@JonathanAllan yes. If a character is non-alphabetic, it's ASCII art must be the '?' art. – Dorian Turba – 2019-12-23T21:21:37.630
@DorianTurba for one less byte total, we we can multiply by
l
inside the comprehension assigned tot
(which is justl*
, once we use an indexing lookup rather than anif-else
) and user[j-l:j]
:) – Jonathan Allan – 2019-12-23T23:00:55.553Yes, I see that in your answer. I remove the comment, thanks. – Dorian Turba – 2019-12-23T23:12:09.093
Is it allowed for the program to terminate with error after printing due to trying to read a line past the last line? – xnor – 2019-12-24T06:07:09.103
@xnor I don't know. You can try the code in the puzzle link provided in my question, the tests are in there. – Dorian Turba – 2019-12-24T06:09:47.933