Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Golfed the output of the ASCII-art generator using the new custom base conversion builtin
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

The below code helps turn ASCII-art into 05AB1E using a custom base compression and transliterateconversion.

|»©ÐÙSDŠ¢øΣθ}R€н¬®sÅ?iD2£RDŠKsì}J©žLR‡®gö5B"•ÿ•"®""ÿ"ÿ"®g"ÿвèJ"«J©žLR‡®gö5B®s"•ÿ•"ÿ"ÅвJ"

Try it online. Try it online.

  1. Listing out the unique characters in the ASCII drawing.
  2. Order them withby how many times they occur in the onesstring in descending order (most occurring most first so the compressed integer is as small as possibleto least occurring characters).
  3. Reverse the first two items if the ASCII drawing starts with the most occurring character (to prevent leading 0s in the compressed integer).
  4. Map the characters of the input to 0-9A-Za-z in that order, each distinct character getting its own mapping-character, until every one has been replaced.
  5. Base compress it, using the highest base you needed to replace (based on the amount of unique characters).
  6. Base convert it again to base-255 (for 05AB1E compression).
  7. Format everything in the format: "<sorted_distinct_characters>"•<compressed_integer>•<integer>вèJ•<compressed_integer>•"<sorted_distinct_characters>"ÅвJ.

The " allows you to also compress string-quotes "; the •<compressed_integer>•<integer>в will generate a list of integers; èÅв will index these integers inuse this string to base-convert the generated integer using the string "<sorted_distinct_characters>";as custom base; and J will join all these characters together to a single string, which is output implicitly.

#05AB1E, 108106 bytes

"─ └┘┐┌
XBA"•I£•I£.μ*:]ó±øqaμb4ΘYQmœ1μû4p ́ζÂĆ_×ばつðòË|4#1¶úôÂ-Í| ̄ε1⁄4É2ïδ&×ばつHÃBjý2ĆÉ≠FYÂÂèC j‘£Å5Œ•10вèJj‘£Å5Œ•"─ └┘┐┌
XBA"ÅвJ

Try it online. Try it online.

*(108106/214)100 = 5049.47%53% the size of the original ASCII-art string.

Which is only 2 bytes longer thanthe same byte-count as my actual submission for that challenge in 05AB1E (legacy).

|» # Take multi-line input
 © # Store it in the register to reuse later 
ÐÙS # Only leave unique characters (as list)
 DŠ¢ø # Map it with the count for each of those characters
 Σθ}R # Sort it based on that count (highest to lowest)
 €н # Remove the count again, so the sorted characters remain
¬®sÅ?i # If the input starts with the most occurring character:
 D2£RDŠKsì} # Swap the first two characters in the list
J© # Join everything together, and store it in the register to reuse later
 žLR‡ # Map each character to [0-9A-Za-z]
 ®gö # Get the amount of unique characters, and convert it to that Base
 5B # And then convert that to Base-255
"•ÿ•" ®s # Put that compressed integer between # Push the string and ®""ÿ"ÿ"swap so the compressed integer #is Putat the stringtop betweenagain
 ", and"•ÿ•"ÿ"ÅвJ" append the compressed integer
®g"ÿвèJ"# Insert it in the correct output format
 # Create a string with the amount of unique characters, followed by "вèJ"
 # `•<compressed_integer>•"<sorted_distinct_characters>"ÅвJ`
"•ÿ•" « # And append# it(after towhich the stringresult andis compressedoutput integer,implicitly andwith ouputtrailing implicitlynewline)

The below code helps turn ASCII-art into 05AB1E using base compression and transliterate.

|»©ÐÙSDŠ¢øΣθ}R€н¬®sÅ?iD2£RDŠKsì}J©žLR‡®gö5B"•ÿ•"®""ÿ"ÿ"®g"ÿвèJ"«

Try it online.

  1. Listing out the unique characters in the ASCII drawing.
  2. Order them with the ones occurring most first so the compressed integer is as small as possible.
  3. Reverse the first two items if the ASCII drawing starts with the most occurring character (to prevent leading 0s in the compressed integer).
  4. Map the characters of the input to 0-9A-Za-z in that order, each distinct character getting its own mapping-character, until every one has been replaced.
  5. Base compress it, using the highest base you needed to replace (based on the amount of unique characters).
  6. Base convert it again to base-255 (for 05AB1E compression).
  7. Format everything in the format: "<sorted_distinct_characters>"•<compressed_integer>•<integer>вèJ.

The " allows you to also compress string-quotes "; the •<compressed_integer>•<integer>в will generate a list of integers; è will index these integers in the string "<sorted_distinct_characters>"; and J will join all these characters together to a single string, which is output implicitly.

#05AB1E, 108 bytes

"─ └┘┐┌
XBA"•I£.μ*:]ó±øqaμb4ΘYQmœ1μû4p ́ζÂĆ_×ばつðòË|4#1¶úôÂ-Í| ̄ε1⁄4É2ïδ&×ばつHÃBjý2ĆÉ≠FYÂÂèC j‘£Å5Œ•10вèJ

Try it online.

*(108/214)100 = 50.47% the size of the original ASCII-art string.

Which is only 2 bytes longer than my actual submission for that challenge in 05AB1E.

|» # Take multi-line input
 © # Store it in the register to reuse later 
ÐÙS # Only leave unique characters (as list)
 DŠ¢ø # Map it with the count for each of those characters
 Σθ}R # Sort it based on that count (highest to lowest)
 €н # Remove the count again, so the sorted characters remain
¬®sÅ?i # If the input starts with the most occurring character:
 D2£RDŠKsì} # Swap the first two characters in the list
J© # Join everything together, and store it in the register to reuse later
 žLR‡ # Map each character to [0-9A-Za-z]
 ®gö # Get the amount of unique characters, and convert it to that Base
 5B # And then convert that to Base-255
"•ÿ•"  # Put that compressed integer between  ®""ÿ"ÿ" # Put the string between ", and append the compressed integer
®g"ÿвèJ" # Create a string with the amount of unique characters, followed by "вèJ"
 « # And append it to the string and compressed integer, and ouput implicitly

The below code helps turn ASCII-art into 05AB1E using a custom base conversion.

|»©ÐÙSDŠ¢øΣθ}R€н¬®sÅ?iD2£RDŠKsì}J©žLR‡®gö5B®s"•ÿ•"ÿ"ÅвJ"

Try it online.

  1. Listing out the unique characters in the ASCII drawing.
  2. Order them by how many times they occur in the string in descending order (most occurring to least occurring characters).
  3. Reverse the first two items if the ASCII drawing starts with the most occurring character (to prevent leading 0s in the compressed integer).
  4. Map the characters of the input to 0-9A-Za-z in that order, each distinct character getting its own mapping-character, until every one has been replaced.
  5. Base compress it, using the highest base you needed to replace (based on the amount of unique characters).
  6. Base convert it again to base-255 (for 05AB1E compression).
  7. Format everything in the format: •<compressed_integer>•"<sorted_distinct_characters>"ÅвJ.

The " allows you to also compress string-quotes "; the Åв will use this string to base-convert the generated integer using the string as custom base; and J will join all these characters together to a single string, which is output implicitly.

#05AB1E, 106 bytes

•I£.μ*:]ó±øqaμb4ΘYQmœ1μû4p ́ζÂĆ_×ばつðòË|4#1¶úôÂ-Í| ̄ε1⁄4É2ïδ&×ばつHÃBjý2ĆÉ≠FYÂÂèC j‘£Å5Œ•"─ └┘┐┌
XBA"ÅвJ

Try it online.

*(106/214)100 = 49.53% the size of the original ASCII-art string.

Which is the same byte-count as my actual submission for that challenge in 05AB1E (legacy).

|» # Take multi-line input
 © # Store it in the register to reuse later 
ÐÙS # Only leave unique characters (as list)
 DŠ¢ø # Map it with the count for each of those characters
 Σθ}R # Sort it based on that count (highest to lowest)
 €н # Remove the count again, so the sorted characters remain
¬®sÅ?i # If the input starts with the most occurring character:
 D2£RDŠKsì} # Swap the first two characters in the list
J© # Join everything together, and store it in the register to reuse later
 žLR‡ # Map each character to [0-9A-Za-z]
 ®gö # Get the amount of unique characters, and convert it to that Base
 5B # And then convert that to Base-255
®s # Push the string and swap so the compressed integer is at the top again
 "•ÿ•"ÿ"ÅвJ" # Insert it in the correct output format
 # `•<compressed_integer>•"<sorted_distinct_characters>"ÅвJ`
"•ÿ•" # (after which the result is output implicitly with trailing newline)
typo..
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394
  1. Listing out the unique characters in the ASCII drawing.
  2. Order them with the ones occurring most first so the compressed integer is as small as possible.
  3. Reverse the first two items if the ASCII drawing starts with the most occurring character (to prevent trailingleading 0s in the compressed integer).
  4. Map thosethe characters of the input to 0-9A-Za-z in that order, each distinct character getting it'sits own mapping-character, until every one has been replaced.
  5. Base compress it, using the highest base you needed to replace (based on the lengthamount of the unique characters).
  6. Base convert it again to base-255 (for 05AB1E compression).
  7. Format everything in the format: "<sorted_distinct_characters>"•<compressed_integer>•<integer>вèJ.

Which is only 2 bytes longer than my actual submission for that questionmy actual submission for that challenge in 05AB1E.

|» # Take multi-line input
 © # Store it in the register to reuse later 
ÐÙS # Triplicate it, and onlyOnly leave unique characters (as list)
 DŠ¢ø # Map it with the count for each of those characters
 Σθ}R # Sort it based on that count (highest to lowest)
 €н # Remove the count again, so the sorted characters remain
¬®sÅ?i # If the input starts with the most occurring character:
 D2£RDŠKsì} # Swap the first two characters in the list
J© # Join everything together, and store it in the register to reuse later
 žLR‡ # Map each character to [0-9A-Za-z]
 ®gö # Get the amount of unique characters, and convert it to that Base
 5B # And then convert that to Base-255
"•ÿ•" # Put that compressed integer between •
 ®""ÿ"ÿ" # Put the string between ", and append the compressed integer
®g"ÿвèJ" # Create a string with the amount of unique characters, followed by "вèJ"
 « # And append it to the string and compressed integer, and ouput implicitly
  1. Listing out the unique characters in the ASCII drawing.
  2. Order them with the ones occurring most first so the compressed integer is as small as possible.
  3. Reverse the first two items if the ASCII drawing starts with the most occurring character (to prevent trailing 0s in the compressed integer).
  4. Map those characters to 0-9A-Za-z in that order, each distinct character getting it's own mapping-character, until every one has been replaced.
  5. Base compress it, using the highest base you needed to replace (based on the length of the unique characters).
  6. Base convert it again to base-255 (for 05AB1E compression).
  7. Format everything in the format: "<sorted_distinct_characters>"•<compressed_integer>•<integer>вèJ.

Which is only 2 bytes longer than my actual submission for that question in 05AB1E.

|» # Take multi-line input
 © # Store it in the register to reuse later 
ÐÙS # Triplicate it, and only leave unique characters (as list)
 DŠ¢ø # Map it with the count for each of those characters
 Σθ}R # Sort it based on that count (highest to lowest)
 €н # Remove the count again, so the sorted characters remain
¬®sÅ?i # If the input starts with the most occurring character:
 D2£RDŠKsì} # Swap the first two characters in the list
J© # Join everything together, and store it in the register to reuse later
 žLR‡ # Map each character to [0-9A-Za-z]
 ®gö # Get the amount of unique characters, and convert it to that Base
 5B # And then convert that to Base-255
"•ÿ•" # Put that compressed integer between •
 ®""ÿ"ÿ" # Put the string between ", and append the compressed integer
®g"ÿвèJ" # Create a string with the amount of unique characters, followed by "вèJ"
 « # And append it to the string and compressed integer, and ouput implicitly
  1. Listing out the unique characters in the ASCII drawing.
  2. Order them with the ones occurring most first so the compressed integer is as small as possible.
  3. Reverse the first two items if the ASCII drawing starts with the most occurring character (to prevent leading 0s in the compressed integer).
  4. Map the characters of the input to 0-9A-Za-z in that order, each distinct character getting its own mapping-character, until every one has been replaced.
  5. Base compress it, using the highest base you needed to replace (based on the amount of unique characters).
  6. Base convert it again to base-255 (for 05AB1E compression).
  7. Format everything in the format: "<sorted_distinct_characters>"•<compressed_integer>•<integer>вèJ.

Which is only 2 bytes longer than my actual submission for that challenge in 05AB1E.

|» # Take multi-line input
 © # Store it in the register to reuse later 
ÐÙS # Only leave unique characters (as list)
 DŠ¢ø # Map it with the count for each of those characters
 Σθ}R # Sort it based on that count (highest to lowest)
 €н # Remove the count again, so the sorted characters remain
¬®sÅ?i # If the input starts with the most occurring character:
 D2£RDŠKsì} # Swap the first two characters in the list
J© # Join everything together, and store it in the register to reuse later
 žLR‡ # Map each character to [0-9A-Za-z]
 ®gö # Get the amount of unique characters, and convert it to that Base
 5B # And then convert that to Base-255
"•ÿ•" # Put that compressed integer between •
 ®""ÿ"ÿ" # Put the string between ", and append the compressed integer
®g"ÿвèJ" # Create a string with the amount of unique characters, followed by "вèJ"
 « # And append it to the string and compressed integer, and ouput implicitly
Improved the output of the ASCII-art generator, and also allowing string-quotes in the ASCII-art
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394
`|»D꩞LR‡®gö255B"•"s"•"®g"BžLR"34ç®34ç"‡"J|»©ÐÙSDŠ¢øΣθ}R€н¬®sÅ?iD2£RDŠKsì}J©žLR‡®gö5B"•ÿ•"®""ÿ"ÿ"®g"ÿвèJ"«

Try it online 1! Try it online.

  1. Listing out the unique characters in the ASCII drawing.
  2. UsingOrder them with the dictionaryones occurring most first so the compressed integer is as small as possible.
  3. Reverse the first two items if the ASCII drawing starts with the most occurring character (to prevent trailing 0s in the compressed integer).
  4. Map those characters to 0-9A-ZZa-z, replace all ASCII chars in the drawing with one of these letters starting with 0 and goingthat order, each distinct character getting it's own mapping-character, until you don't need anymore charsevery one has been replaced.
  5. Base compress it, using the highest base you needed to replace (16 chars = hexidecimalbased on the length of the unique characters).
  6. Base convert it again to base-255 (for 05AB1E compression).
  7. Put itFormat everything in betweenthe format: "<sorted_distinct_characters>"•<compressed_integer>•<integer>вèJ symbols then use 05AB1E to reverse the process.

The " allows you to also compress string-quotes "; the •<compressed_integer>•<integer>в will generate a list of integers; è will index these integers in the string "<sorted_distinct_characters>"; and J will join all these characters together to a single string, which is output implicitly.

Accepts patterns with less thanup to and including 62 unique characters, good for ASCII-ARTart.

The
The less numberamount of unique characters, the better the compression.

Example output for Draw the XNOR digital timing diagram (222214 bytes, 9 unique charscharacters):

 ┌─┐ ┌─┐ ┌─────┐ ┌─┐ ┌─┐ ┌───┐ 
A ──┘ └─┘ └─┘ └─┘ └─┘ └─┘ └──
 ┌───┐ ┌───┐ ┌─┐ ┌─────┐ ┌─┐ ┌─┐
B ┘ └─┘ └─┘ └─┘ └───┘ └─┘ └
 ┌─────┐ ┌─┐ ┌─┐ ┌───┐ 
X ──┘ └───┘ └───┘ └───┘ └────

05AB1E , 113 bytes

#05AB1E , 108 bytes

•1V§pĆÿhÅYΣ3ćâÖ#ˆ§.../rë-£ÙvмÇ!ovÉ®~.bδ„§"o∞ŸÂZö≠тA¿44ÇΩÝγ»"[øΩÓ›f∍Sôâ ̄ ̄6ÔðŠŒζιËp"─ └┘┐┌
øδVØß„q[ÙXBA"•I£.μ*:]ó±øqaμb4ΘYQmœ1μû4p ́ζÂĆ_×ばつðòË|4#1¶úôÂ-тËK•10BžLR"
Í| ̄ε1⁄4É2ïδ&×ばつHÃBjý2ĆÉ≠FYÂÂèC ABX─┌┐└┘"‡j‘£Å5Œ•10вèJ

Try it online 2! Try it online.

113/222 = 50.90% the Size of the Original. *(108/214)100 = 50.47% the size of the original ASCII-art string.

Which is only 72 bytes longer than my actual submission for that question in 05AB1E.

#Explained#Code explanation:

|» # Take input, separated by newlines.
 Dê© # Find unique characters.
 žLR # Push [0-9A-Z].
 ‡ # Replace each character in input with unique character.
 ®gö255B # Convert from minimal required base into base-255.
 "•"s"•"®g"BžLR"34ç®34ç"‡"J # Surround with '•', push translation table and join.

NOTE: Code is absolutely not golfed. It's quickly written to convert ASCII art to the most efficient compression, so it's quite ugly and long..

|» # Take multi-line input
 © # Store it in the register to reuse later 
ÐÙS # Triplicate it, and only leave unique characters (as list)
 DŠ¢ø # Map it with the count for each of those characters
 Σθ}R # Sort it based on that count (highest to lowest)
 €н # Remove the count again, so the sorted characters remain
¬®sÅ?i # If the input starts with the most occurring character:
 D2£RDŠKsì} # Swap the first two characters in the list
J© # Join everything together, and store it in the register to reuse later
 žLR‡ # Map each character to [0-9A-Za-z]
 ®gö # Get the amount of unique characters, and convert it to that Base
 5B # And then convert that to Base-255
"•ÿ•" # Put that compressed integer between •
 ®""ÿ"ÿ" # Put the string between ", and append the compressed integer
®g"ÿвèJ" # Create a string with the amount of unique characters, followed by "вèJ"
 « # And append it to the string and compressed integer, and ouput implicitly
`|»D꩞LR‡®gö255B"•"s"•"®g"BžLR"34ç®34ç"‡"J

Try it online 1!

  1. Listing out the unique characters in the ASCII drawing.
  2. Using the dictionary 0-9A-Z, replace all ASCII chars in the drawing with one of these letters starting with 0 and going until you don't need anymore chars.
  3. Base compress it, using the highest base you needed to replace (16 chars = hexidecimal).
  4. Base convert it again to base-255 (for 05AB1E compression).
  5. Put it in between symbols then use 05AB1E to reverse the process.

Accepts patterns with less than 62 unique characters, good for ASCII-ART.

The less number of unique characters, the better the compression.

Example output for Draw the XNOR digital timing diagram (222 bytes, 9 unique chars):

 ┌─┐ ┌─┐ ┌─────┐ ┌─┐ ┌─┐ ┌───┐ 
A ──┘ └─┘ └─┘ └─┘ └─┘ └─┘ └──
 ┌───┐ ┌───┐ ┌─┐ ┌─────┐ ┌─┐ ┌─┐
B ┘ └─┘ └─┘ └─┘ └───┘ └─┘ └
 ┌─────┐ ┌─┐ ┌─┐ ┌───┐ 
X ──┘ └───┘ └───┘ └───┘ └────

05AB1E , 113 bytes

•1V§pĆÿhÅYΣ3ćâÖ#ˆ§.../rë-£ÙvмÇ!ovÉ®~.bδ„§"o∞ŸÂZö≠тA¿44ÇΩÝγ»"[øΩÓ›f∍Sôâ ̄ ̄6ÔðŠŒζιËp
øδVØß„q[Ù-тËK•10BžLR"
 ABX─┌┐└┘"‡

Try it online 2!

113/222 = 50.90% the Size of the Original.

Which is only 7 bytes longer than my actual submission for that question in 05AB1E.

#Explained:

|» # Take input, separated by newlines.
 Dê© # Find unique characters.
 žLR # Push [0-9A-Z].
 ‡ # Replace each character in input with unique character.
 ®gö255B # Convert from minimal required base into base-255.
 "•"s"•"®g"BžLR"34ç®34ç"‡"J # Surround with '•', push translation table and join.
|»©ÐÙSDŠ¢øΣθ}R€н¬®sÅ?iD2£RDŠKsì}J©žLR‡®gö5B"•ÿ•"®""ÿ"ÿ"®g"ÿвèJ"«

Try it online.

  1. Listing out the unique characters in the ASCII drawing.
  2. Order them with the ones occurring most first so the compressed integer is as small as possible.
  3. Reverse the first two items if the ASCII drawing starts with the most occurring character (to prevent trailing 0s in the compressed integer).
  4. Map those characters to 0-9A-Za-z in that order, each distinct character getting it's own mapping-character, until every one has been replaced.
  5. Base compress it, using the highest base you needed to replace (based on the length of the unique characters).
  6. Base convert it again to base-255 (for 05AB1E compression).
  7. Format everything in the format: "<sorted_distinct_characters>"•<compressed_integer>•<integer>вèJ.

The " allows you to also compress string-quotes "; the •<compressed_integer>•<integer>в will generate a list of integers; è will index these integers in the string "<sorted_distinct_characters>"; and J will join all these characters together to a single string, which is output implicitly.

Accepts patterns with up to and including 62 unique characters, good for ASCII-art.
The less amount of unique characters, the better the compression.

Example output for Draw the XNOR digital timing diagram (214 bytes, 9 unique characters):

 ┌─┐ ┌─┐ ┌─────┐ ┌─┐ ┌─┐ ┌───┐ 
A ──┘ └─┘ └─┘ └─┘ └─┘ └─┘ └──
 ┌───┐ ┌───┐ ┌─┐ ┌─────┐ ┌─┐ ┌─┐
B ┘ └─┘ └─┘ └─┘ └───┘ └─┘ └
 ┌─────┐ ┌─┐ ┌─┐ ┌───┐ 
X ──┘ └───┘ └───┘ └───┘ └────

#05AB1E , 108 bytes

"─ └┘┐┌
XBA"•I£.μ*:]ó±øqaμb4ΘYQmœ1μû4p ́ζÂĆ_×ばつðòË|4#1¶úôÂ-Í| ̄ε1⁄4É2ïδ&×ばつHÃBjý2ĆÉ≠FYÂÂèC j‘£Å5Œ•10вèJ

Try it online.

*(108/214)100 = 50.47% the size of the original ASCII-art string.

Which is only 2 bytes longer than my actual submission for that question in 05AB1E.

#Code explanation:

NOTE: Code is absolutely not golfed. It's quickly written to convert ASCII art to the most efficient compression, so it's quite ugly and long..

|» # Take multi-line input
 © # Store it in the register to reuse later 
ÐÙS # Triplicate it, and only leave unique characters (as list)
 DŠ¢ø # Map it with the count for each of those characters
 Σθ}R # Sort it based on that count (highest to lowest)
 €н # Remove the count again, so the sorted characters remain
¬®sÅ?i # If the input starts with the most occurring character:
 D2£RDŠKsì} # Swap the first two characters in the list
J© # Join everything together, and store it in the register to reuse later
 žLR‡ # Map each character to [0-9A-Za-z]
 ®gö # Get the amount of unique characters, and convert it to that Base
 5B # And then convert that to Base-255
"•ÿ•" # Put that compressed integer between •
 ®""ÿ"ÿ" # Put the string between ", and append the compressed integer
®g"ÿвèJ" # Create a string with the amount of unique characters, followed by "вèJ"
 « # And append it to the string and compressed integer, and ouput implicitly
Codepage maximum of 214 changed to 255
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394
Loading
Source Link
Magic Octopus Urn
  • 20.9k
  • 6
  • 66
  • 140
Loading

AltStyle によって変換されたページ (->オリジナル) /