The challenge
Given two strings, each of length up to 30, consisting of printable ASCII characters (codes \$[32, 126]\$), put them onto a balance scale in the fewest bytes of code! This consists of the following steps:
- Calculate and compare the weights of the strings
- Choose the appropriately tilted ASCII-art scale
- Place the two strings onto the scale
The strings may be passed as an array, two arguments, or any other reasonable method.
The weight of a string is defined as the sum of the weights of that string's characters, where:
- Spaces have a weight of 0 (
)
- Lowercase letters have a weight of 2 (
abcdefghijklmnopqrstuvwxyz
) - Uppercase letters have a weight of 4 (
ABCDEFGHIJKLMNOPQRSTUVWXYZ
) - All other symbols have a weight of 3 (
!"#$%&'()*+,-./0123456789:;<=>?@[\]^_`{|}~
)
The scales look like this:
. _ | _-*/\ |-* / \ _-*| / \ _-* | / \ /\ | *------* / \ | / \ | / \ | *------* | ______|______
_ . /\*-_ | / \ *-| / \ |*-_ / \ | *-_ *------* | /\ | / \ | / \ | / \ | *------* ______|______
. | ______|______ /\ | /\ / \ | / \ / \ | / \ / \ | / \ *------* | *------* | | ______|______
If the first string is heavier, use the first drawing as the base of your output; if the second string is heavier, use the second drawing; if the strings have equal weight, use the third. Trailing whitespace is allowed.
I will be using a segment of the third drawing as the base for all of the following examples.
The first string should be placed onto the left pan, and the second string onto the right pan.
Place a string on a pan by placing its non-space characters within the 6x5 area immediately above the dashes, as marked by #
s here (you may end up overwriting part of the balance scale - that is fine):
######_ ###### ###### ###### /######\ *------*
All of these characters should be "settled" ie. either above a -
character or another character from the string:
WRONG WRONG CORRECT ____ ____ ____ f /\ /\ /\ l \ / \ / \ / \ / hov\ / s \ /oating\ /eri ng\ /ettled\ *------* *------* *------*
Additionally, the whole stack should be as flat as possible, meaning that of the six 1-wide columns, the height of the tallest and the height of the shortest must not differ by more than 1:
WRONG WRONG CORRECT CORRECT [tallest: 5] [tallest: 4] [tallest: 5] [tallest: 2] [shortest: 0] [shortest: 2] [shortest: 4] [shortest: 2] 5__5_ ____ 5_5__ ____ 45445 & /\ 445454 /\ 45445 $% &$@ 445454 / \ /45445 &%@%$& 445454 %&$@%& / 45445\ /&$@$&%\ /445454\ /$@$%$$\ *------* *------* *------* *------*
The exact order/arrangement of the characters does not matter. The following are all valid arrangements for the string "Weigh your words!":
____ ____ ____ ____ /\ /\ /\ /\ ds! \ / owd oe \u !Wd \ ourwor Wihuos yoiwgr eghioo /Weighy\ /egyrr!\ /Wrhd!s\ /rrsuwy\ *------* *------* *------* *------*
Test cases
INPUT: "CODE GOLF", "coding challenges" WEIGHTS: 32, 32 EXAMPLE OUTPUT: . | ______|______ /\ | /\ / \ | nge\s /OO \ | challe /CFGLED\ | /coding\ *------* | *------* | | ______|______
INPUT: "", "$" WEIGHTS: 0, 3 EXAMPLE OUTPUT: _ . /\*-_ | / \ *-| / \ |*-_ / \ | *-_ *------* | /\ | / \ | / \ | / $ \ | *------* ______|______
INPUT: "YOU KNOW WHAT THEY SAY!", "there's_always_a_relevant_xkcd" WEIGHTS: 75, 65 EXAMPLE OUTPUT: . tr_a_s | _hekx_y |-* elcdta _-*| revanw _-* | /e's_al\ T/\ | *------* AUYOHY | A!HWYK | /OTSMEW\ | *------* | ______|______
+1
. Firstly: if spaces don't "weigh" anything and don't get included in the artwork then why include them at all? It's just unnecessary overhead to first filter them out. Secondly: this feels like a "2-in-1"/chameleon challenge to me - Challenge 1: Determine which string is "heavier", Challenge 2: Generate some ASCII-art. \$\endgroup\$