Staq, 72 characters
't't't't{aii*XX}$&iia$&ia$&a+XX+XX+|{mxx}{lxX}{k>?m!l}kkk&iiqi&ii*s*t|+:
Example run:
Executing D:\codegolf\Staq\sjoelen codegolf.txt
3
5
4
3
70
Execution complete.
>
Staq has two stacks, one active, one passive. The |
command switches the active stack to passive and vice versa.
Everything between curly braces defines a function, the first letter after the opening brace is the function name, the rest until the closing brace is the function itself. Overriding functions, recursion and nested functions are possible. {aii}
would define a function a that would increment the top of the stack twice. Every following instance of a
in the code will be replaced by ii
.
Comments inside Staq prorams:
&
adds a zero on top of the stack, [
instructs the pointer to jump to the corresponding ]
if the top of the stack is zero, x
deletes the topmost value on the stack. So, comments can be written into the code in the form of &[here is a comment]x
Explanation (also executable):
' &[input number]x
t &[copy top of active stack to passive stack]x
t't't &[input next three numbers and copy them to the passive stack]x
{aii*XX} &[define function a (increment twice, multiply the two topmost values, then delete the second value on the stack twice)]x
$ &[move top value to the bottom of the stack]x
&ii &[put zero on top of the stack, incremment twice]x
a &[function a]x
$&ia$&a
+ &[put sum of the two topmost values on top of the stack]x
XX &[delete second stack value, twice]x
+XX+
| &[switch active/passive stack]x
{mxx} &[define function m: delete two topmost stack values]x
{lxX} &[define function l: delete topmost stack value, then delete second value of remaining stack]x
{k>?m!l} &[define function k: boolean top > second value? put result on top of the stack, if top>0 then execute m, if top = 0 then execute l]x
kkk&ii
q &[put square of top value on top of the stack]x
i&ii
* &[multiply two topmost values and put result on top of the stack]x
s &[move bottom stack value to the top]x
*t|+
: &[output result]x
https://esolangs.org/wiki/Staq
The program uses one stack (initially active) to calculate 2a+3b+4c+d, and the second stack (initially passive) to calculate 10 times the minimum of the input values. Then both results are summed up and displayed.