Code Golf Asked by Katenkyo on January 4, 2022
Don’t you find that reading simple text isn’t appealing enough? Try our
##### ### ### ##### ##### ##### ##### # # ##### #
# # # # # # # # # # # # #
##### ### # # # # #### # # #
# # # # # # # # # # # #
# # ### ### ##### ##### # ##### # # # #
Much more fancy isn’t it? But it’s pretty long to write by hand, it would be wonderful if someone did a program that do it for me !
Your task, if you volunteer to help me, will be to write a program or a function that takes a string containing [a-zA-Zsn]
only, and output (or return) the ascii writing of it!
You must use the following alphabet to format your output:
##### #### ### #### ##### ##### ### # # ##### ##### # # # # #
# # # # # # # # # # # # # # # # # # ## ##
##### #### # # # #### #### # ## ##### # # ### # # # #
# # # # # # # # # # # # # # # # # # # # # #
# # #### ### #### ##### # ### # # ##### ### # # ##### # #
# # ### #### ### #### ### ##### # # # # # # # # # # #####
## # # # # # # # # # # # # # # # # # # # # # #
# # # # # #### # # #### ### # # # # # # # # # # #
# ## # # # # ## ## # # # # # # ## ## # # # #
# # ### # #### # # ### # ### # # # # # # #####
The space:
|
| it's a 5x5 square of spaces
| but had to pad it with |s to make it appear in this post
|
|
As this is a fixed-width font, the space character is also surrounded by spaces, resulting in a 7-width space between the two letters.
a b
1234567 -- these numbers are just for the example, you don't have to output them
##### ####
# # # #
##### ####
# # # #
# # ####
a b
1234567890123
##### ####
# # # #
##### ####
# # # #
# # ####
When you encounter a newline, as in the input
ascii
text
Just make sure to separate the two blocks of text by at least one empty line
##### ### ### ##### #####
# # # # # # #
##### ### # # #
# # # # # # #
# # ### ### ##### #####
##### ##### # # #####
# # # # #
# #### # #
# # # # #
# ##### # # #
Also, you are allowed to replace the #
s with any other character as long as it is in the printable ASCII range, and is not spaces. You could for instance use A
s for the letter A, B
for the letter B and so on.
As this is code-golf (and moreover kolmogorov-complexity) the winning submission will be the one that solve this challenge in the least byte possible, have fun!
$args-split'
'|%{$s=$_
0..5|%{$l=$_
-join($s|% *per|% t*y|%{$c='_ONO__NQ__QAQQNONON_QQQQQ?QQQQAAAQDDIA[SQQQQADQQQJJ(_OAQOOY_DDGAUUQOQONDQJUDD$QQQQAAQQDEEAQYQAYCPDQJ[JD"QONO_ANQ_GI_QQNA^ENDNDQQD?'[$l*26+$_-65+222*!($_-32)]
0..5|%{' #'[(+$c-shr$_)%2]}})}}
Test script:
$f = {
$args-split'
'|%{$s=$_
0..5|%{$l=$_
-join($s|% *per|% t*y|%{$c='_ONO__NQ__QAQQNONON_QQQQQ?QQQQAAAQDDIA[SQQQQADQQQJJ(_OAQOOY_DDGAUUQOQONDQJUDD$QQQQAAQQDEEAQYQAYCPDQJ[JD"QONO_ANQ_GI_QQNA^ENDNDQQD?'[$l*26+$_-65+222*!($_-32)]
0..5|%{' #'[(+$c-shr$_)%2]}})}}
}
&$f "ascii art
text"
Output:
##### ### ### ##### ##### ##### #### #####
# # # # # # # # # # # #
##### ### # # # ##### #### #
# # # # # # # # # ## #
# # ### ### ##### ##### # # # # #
##### ##### # # #####
# # # # #
# #### # #
# # # # #
# ##### # # #
$s|% *per|% t*y
is shortcut for $s|% toUpper|% toCharArray
For each character of the source string, the script takes a symbol (bit mask) from the magic string '_ONO__NQ...'
. However, the index goes beyond the magic string for a space. In this case, the bit mask $c
becomes empty. It means zero for all bits.
The script displays 6 rows for each symbol instead of 5. The index goes beyond the magic string for a blank line too. So, the row 6 contains spaces only.
It is best seen if you print another character instead of a space. For example ·
.
#####··###···###··#####·#####·······#####·####··#####·
#···#·#·····#···#···#·····#·········#···#·#···#···#···
#####··###··#·······#·····#·········#####·####····#···
#···#·····#·#···#···#·····#·········#···#·##······#···
#···#··###···###··#####·#####·······#···#·#·#·····#···
······················································
#####·#####·#···#·#####·
··#···#······#·#····#···
··#···####····#·····#···
··#···#······#·#····#···
··#···#####·#···#···#···
························
Answered by mazzy on January 4, 2022
-8 bytes thanks to ceilingcat
#define X!!putchar
char*p,*q;i,j;f(int*s){for(;p=strtok(p?0:strdup(s),"n");X(10))for(i=0;i<5;i+=X(10))for(q=p;*q;q+=X(32))for(j=0;j<5;)X((*q-32?"OAOAA?A?A?>A1A>?AAA?O1?1OO1?11>1IA>AAOAAO444OO4457A97591111OAKEAAACCIA>AAA>?A?11>AAIN?A?35>1>@>O4444AAAA>AA::4AAEKAA:4:AA:444O842O"[(*q&~32)*5-325+i]-48:0)>>j++&1?35:32);}
Answered by gastropner on January 4, 2022
s=>s.split`
`.map(s=>`vfefvvehvvh1hhefefevhhhhhv
hhhh111h4491rjhhhh14hhhaa8
vf1hffpv4471llhfhfe4hal444
hhhh11hh4551hph1p3g4hara42
hfefv1ehv79vhhe1u5e4e4hh4v`.replace(/.{26}/g,S=>s.replace(/./g,c=>'012345'.replace(/./g,x=>' #'[(P=parseInt)(S[P(c,36)-10]||0,36)>>x&1])))).join`
`
let f =
s=>s.split`
`.map(s=>`vfefvvehvvh1hhefefevhhhhhv
hhhh111h4491rjhhhh14hhhaa8
vf1hffpv4471llhfhfe4hal444
hhhh11hh4551hph1p3g4hara42
hfefv1ehv79vhhe1u5e4e4hh4v`.replace(/.{26}/g,S=>s.replace(/./g,c=>'012345'.replace(/./g,x=>' #'[(P=parseInt)(S[P(c,36)-10]||0,36)>>x&1])))).join`
`
O.innerText = f('HELLO WORLDnTHIS IS A TEST')
<pre id=O></pre>
Answered by Arnauld on January 4, 2022
°f`7-π⅛χ%sΤ↕ņLRΕ⅓9׀b∫rr(¶æKGTΧ3;■ΦΤg¼⁰¡Νg‽}○eΧ²Y∫Οαν⌡l′}¾(8╔ <%╤∙i.d↔ū∫Æo┌jyŗ▲δ⁶=╗$↑yōΛ3h¼╔◄┼)‘’«n.{5{ø}¹,uR{8+:Ahwha’#=?X’«@*}┼L@*┼}pøO
Explanation:
...‘’«n.{5{ø}¹,uR{8+:Ahwha’#=?X’«@*}┼L@*┼}pøO
...‘ push a string with the letter data ["..."]
’«n split in lengths of 25 [[".", ".", ".",...]]
.{ repeat input times [[".", ".", ".",...]]
5{ø} push 5 empty strings [[".", ".", ".",...], "", "", "", "", ""]
¹ wrap those in an array [[".", ".", ".",...], ["", "", "", "", ""]]
, get a string input [[".", ".", ".",...], ["", "", "", "", ""], "Hello World"]
u lowercase it [[".", ".", ".",...], ["", "", "", "", ""], "hello world"]
R{ } itirate over the ordinals of the string [[".", ".", ".",...], ["", "", "", "", ""], 104]
8+ add 8 to the ordinal [[".", ".", ".",...], ["", "", "", "", ""], 112]
:A save on variable A [[".", ".", ".",...], ["", "", "", "", ""], 112]
h swap 2 items one below the stack [["", "", "", "", ""], [".", ".", ".",...], 112]
w get the ord+8th item of the letter data array (modulo length) [["", "", "", "", ""], [".", ".", ".",...], "----- - - - -----"]
h swap 2 items one below the stack [[".", ".", ".",...], ["", "", "", "", ""], "----- - - - -----"]
a load the variable A [[".", ".", ".",...], ["", "", "", "", ""], "----- - - - -----", 112]
’#=? } if equals to 40 then [[".", ".", ".",...], ["", "", "", "", ""], "----- - - - -----"] (temporalily switching to space case; it incorrectly picks "N" for space)
X delete the string [[".", ".", ".",...], ["", "", "", "", ""]]
’«@* push a string with 25 spaces [[".", ".", ".",...], ["", "", "", "", ""], " "]
┼ add the string vertically-then-horizontally to the array [[".", ".", ".",...], ["", "", "", "", ""], ["- -", "- -", "-----", "- -", "- -"]] (back to "H")
L@* push a string with 10 spaces [[".", ".", ".",...], ["", "", "", "", ""], ["- -", "- -", "-----", "- -", "- -"], " "]
┼ add the string vertically-then-horizontally to the array [[".", ".", ".",...], ["", "", "", "", ""], ["- - ", "- - ", "----- ", "- - ", "- - "]]
p output the resulted line [[".", ".", ".",...], ["", "", "", "", ""]]
øO append to output an empty line
note: currently this language can't really accept multiline input string so I've made it ask for a number and read the next x lines as the input.
The first string is
"------ - - - - - ----------- - -- - -- - - - - --- - -- -- - - - ------ -- -- - --- ------ - -- - -- - -- ------- - - - - - - --- - -- -- - - -- ----- - - - ------ -- ------- -- -- --- ------- - ----- - -- - -- ----- - - - ------ - - - ---------- - - - ----- --- - -- -- - --- ------ - - - - - - --- - -- -- -- ---------- -- - - -- - - - - - -- - -- - - - - - ------ - ---- - - ----- -- -- - -- -- ----- - - - ------ - - - - - - - -- - --- - - - -- --- - --- -- -"
compressed using a custom dictionary that uses " " and "-" (the compression has a special mode with "n -|/_" available so even more compression!)
It contains 25 chars per ascii char in the order of the alphabet. they are ordered top-down then right.
the chars go like
16b
27c
38d . . .
49e
5af
and that's the same way that ┼
adds them to an array.
Answered by dzaima on January 4, 2022
f=lambda i:"nn".join("n".join(map(" ".join,zip(*[[x.replace("0"," ")[a*5:a*5+5]for a in range(5)]for x in[["{:025b}".format(int(c,36))for c in'0 JPCFL J2UKE 92Y3Y J2KAM JOMCF JOMC0 92B72 AYP81 JFM3J JFMHO AZC7M AB6ZJ B5I5T B43N5 92YWE J2UJ4 92YY7 J2UQC 926UM JFM2S AYE5Q AY8G4 AYHKH AT6Q9 AT6KK AWU7'.split()][x!=" "and ord(x)-64]for x in j.upper()]])))for j in i.split("n"))
See this code running on ideone.com.
The same code, but somehow nicely indented, formatted and commented:
f = lambda i:
# join multiline strings together using an empty line as separator:
"nn".join(
# join the string lines of one big output line together:
"n".join(
# join the corresponding rows of the letters together using " ":
map(" ".join, zip(*
# make a list (output line) of list (output characters)
# of strings (single character's rows):
[
# replace 0s with spaces and split the bit strings into
# chunks of 5 characters - the rows of each letter:
[x.replace("0", " ")[a*5 : a*5+5] for a in range(5)]
for x in [
# split the space separated character codes and
# convert them from base 36 to
# base 2 strings of length 25:
["{:025b}".format(int(c, 36)) for c in
# the encoded font data (reformatted):
'0 JPCFL J2UKE 92Y3Y J2KAM JOMCF JOMC0 92B72 '
'AYP81 JFM3J JFMHO AZC7M AB6ZJ B5I5T B43N5 92YWE '
'J2UJ4 92YY7 J2UQC 926UM JFM2S AYE5Q AY8G4 AYHKH '
'AT6Q9 AT6KK AWU7'.split()]
# select element 0 if we want a space, else find
# out the index from the ASCII code of the letter:
[x != " " and ord(x) - 64]
# repeat for every character in the input line:
for x in j.upper()
]
]
))
# repeat for every line in the input
) for j in i.split("n")
)
I also decided to go for base 36 encoding as that's the highest base Python's built-in int()
natively supports. Here is a short Python 3 script I wrote (ungolfed) that converts font definitions like in the question into base 36 codes: My converter on ideone.com
The result consists of the character 1
as enabled pixel and a space
as disabled pixel. Here's a single example run:
Input (line break as n
):
Hello World
Python rocks
Output:
1 1 11111 1 1 111 1 1 111 1111 1 1111
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
11111 1111 1 1 1 1 1 1 1 1 1 1111 1 1 1
1 1 1 1 1 1 1 11 11 1 1 11 1 1 1
1 1 11111 11111 11111 111 1 1 111 1 1 11111 1111
1111 1 1 11111 1 1 111 1 1 1111 111 111 1 1 111
1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1 1
1111 1 1 11111 1 1 1 1 1 1111 1 1 1 111 111
1 1 1 1 1 1 1 1 11 11 1 1 1 1 1 1 1
1 1 1 1 1 111 1 1 1 1 111 111 1 1 111
Answered by Byte Commander on January 4, 2022
(defn t[s](print(reduce #(str %1"n"%2)(map #(apply str %)(let[a[:jpcfl :j2uke :92y3y :j2kam :jomcf :jomc0 :92b72 :ayp81 :jfm3j :jfmho :azc7m :ab6zj :b5i5t :b43n5 :92ywe :j2uj4 :92yy7 :j2uqc :926um :jfm2s :aye5q :ay8g4 :ayhkh :at6q9 :at6kk :je7mn :0]](map(fn[o](map #(str(.replace %"0"" ")"n")(map(fn[w](reduce #(str %1(.substring %2 w(+ w 5))"0")""(map #(str(apply str(repeat(- 25(count %))"0"))%)(map #(Integer/toString(Integer/valueOf(name %)36)2)(map a(map #(if(= % space)26(-(int %)97))(.toLowerCase o)))))))(range 0 25 5))))(.split s"n")))))))
Each letter in ascii is represented as a binary string with # - 1, space - 0. Then it's converted to base 36 so that it only takes 5 chars to store + ":" to let Clojure know that it should be treated as symbol. Then the input is split by newline symbol and for each line we convert a letter in 36 base back to binary base and get first [0:5] symbols add newline symbols, get next [5:10] symbols and so on.
You can see it running here - https://ideone.com/y99ST5
Answered by cliffroot on January 4, 2022
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP