Love Tester Code Golf
Pyth, 40 bytes
jd[z"and"Jw"have"/K-lzl.-rz0rJ0i=J*lzlJK"out of"/JiJK"chances of love.
The code is 70 bytes long and qualifies for the -30 bytes bonus.
Try it online.
[ Begin an array and fill it with the following:
z The first line of input.
"and" That string.
Jw The second line of input, saved in J.
"have" That string.
rz0rJ0 Convert both lines to lowercase.
.- Remove the characters form the second string
from the first, counting multiplicities.
l Get the length.
-lz Subtract it from the length of the first line.
K Save in K.
=J*lzlJ Save the lines' lengths' product in J.
i K Compute the GCD of J and K.
/ The quotient of K and the GCD.
"out of" That string.
/JiJK The quotient of J and the GCD of J and K.
"chances of love. That string.
jd Join the elements, separated by spaces.
CJam, 55 bytes
ll]_~@_{'~,\elfe=}/.e<:+\:,:*]_2>~{_@\%}h;f/"and
have
out of
chances of love."N/.{}S*
The code is 85 bytes long and qualifies for the -30 bytes bonus.
Try it online in the CJam interpreter.
How it works
ll] e# Read two lines and wrap them in an array.
_~ e# Copy the array and dump the lines on the stack.
@_ e# Rotate the array on top and push a copy.
{ e# For each line of the copy.
'~, e# Push the array of all ASCII charcters up to '}'.
\el e# Convert the line to lowercase.
fe= e# Count the occurrences of each character in the line.
}/ e#
.e< e# Vectorized minimum of the occurrences.
:+ e# Add to find the number of shared charaters.
\:, e# Compute the length of each line.
:* e# Push the product.
]_ e# Wrap the stack in an array and push a copy.
2>~ e# Discard the lines of the copy and dump the calculated integers.
{_@\%h}; e# Compute their GCD, using the Euclidean algorithm.
f/ e# Divide each element of the array by the GCD.
e# This also splits the names, which won't affect printing.
"and
have
out of
chances of love."
N/ e# Split the above string at linefeeds.
.{} e# Vectorized no-op. Interleaves the arrays.
S* e# Join the results elements, separated by spaces.
Dyalog APL, 94 91-30= 61 bytes
Usually APL golfing results in code that is more compact – but not more complex – than normal, but in this case I save chars in ugly ways:
{1↓(∊' ',¨⍵,⍪'and' 'have'),' love.',⍨∊((⊢÷∨/)(≢⊃∩/32|⎕ucs¨⍵),×/≢¨⍵),⍪'out of' 'chances of'}
,⍪'out of' 'chances of'
create a 2×2 table of numbers (left) and texts (right)
×/≢¨⍵
product of lengths
32|⎕UCS¨⍵
harmonize upper- and lowercase UCS values
≢⊃∩/
tally the intersection of the two sets
⊢÷∨/
divide the tally and the product with their GCD
,' love.',⍨∊
make it into a simple list and append love.
⍵,⍪'and' 'have'
create a 2×2 table of names (left) and texts (right)
∊' ',¨
prepend a space to each table cell and then make into simple list
1↓
drop the initial superfluous space
Thanks to ngn for -3 bytes.