J, 146 132 134 124
echo'parallel'"_`(1|.')(',[:(,',',])&(0j2&":)/[:,,.@{:%.}:)@.([:*@|[:-/ .*}:)|:".>{.`(<@}:@;@(1 2&{))`{:(`:0)"1;:;._2(1!:1)3
Parsing this is awful.
Edit: Realized that my output is basically broken, although it works for the examples given and parallels...
Edit: Posting the shorter version I already had.
Edit: Fixed without too much pain...
Edit: Fixed a weird issue where the program was spread across multiple lines.
Somewhat ungolfed version:
words =: ;:;._2(1!:1)3
NB. Leverage J's parser itself to split each line into e.g. ax + by = c
lines =: ".>{.`(<@}:@;@(1 2&{))`{:(`:0)"1 words
NB. Use a 3-part gerund (`) to get boxed strings 'ax';'b';'c', unbox and parse
calc_and_format =: 1|.')(',[:(,',',])&(0j2&":)/[:,,.@{:%.}:
NB. %. (matrix multiply) first two rows (a d/b e) by third row turned (c/f)
NB. And then format laboriously. 0j2&": formats numbers with 2 decimals.
det_nonzero =: [:*@|[:-/ .*}:
NB. 1 if determinant (-/ .*) of (a b/d e) is nonzero (*@|)
echo'parallel'"_`calc_and_format@.det_nonzero|: lines
NB. transpose parsed input to get (a d/b e/c f).
NB. If det_nonzero, call calc_and_format, otherwise constant 'parallel'
NB. Print
Ax+By=C
or can it also beAx-By=C
or even-Ax+By=C
? Are negative numbers for A, B or C even allowed? »Print up to two decimal places« implies that less can be printed, your examples do not suggest that. If the output is locale-dependent (which can happen with plenty languages in formatted output), can we assumeen-US
orC
as locale? (I.e. anything that uses a decimal point and not a comma). \$\endgroup\$Ax-By=C
is already given in one of the examples. The points should have 2 decimal places. \$\endgroup\$