Diamond Puzzles!
Jelly, 15 11 10 bytes
Hð+,_ðH²_½
Try it online!
The following binary code works with this version of the Jelly interpreter.
0000000: 48 98 2b 2c 5f 98 48 8a 5f 90 H.+,_.H._.
Idea
This is based on the fact that
Code
Hð+,_ðH²_½ Left input: s -- Right input: p
ð ð This is a link fork. We define three links, call the left and right
link with the input as arguments, then the middle link with the
results as arguments.
H Left link, dyadic. Arguments: s p
H Halve the left input.
ðH²_½ Right link, dyadic. Arguments: s p
H Halve the left input.
² Square the result.
_ Hook; subtract the right input from the result.
½ Apply square root to the difference.
ð+,_ Middle link, dyadic. Arguments: (results of the previous links)
+ Compute the sum of the results.
_ Compute the difference of the results.
, Pair.
Unicorn, 4650 2982 1874 1546
[ ✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨ ( ✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨ ( ) ) 2 ✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨ ( ✨✨✨✨✨✨✨ 4 ✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨ ( ) ) ✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨ ]
Now with goats, rainbows, and sparkles!
Hopefully shorter than Java.
Uses a custom encoding which can be applied with ApplyEncoding
Explanation
How does this work??? With the magic of unicorns (and a little code).
Unicorn is compiled into JavaScript
Each section is separated by a space, and each section represents a character in the JavaScript code.
If the section contains unicorns, the section's character is the section's length, converted to a char code (e.g. 32 unicorns would be a space)
If the section contains goats, the section's length is doubled and then converted to a char code.
If the program's special chars don't show, here's a picture:
This is non competing because Unicorn was made after this challenge was posted.
JavaScript ES6, 45 39 37* bytes
(q,p)=>[x=p/2+Math.sqrt(p*p/4-q),p-x]
* Thanks to Dennis!