⬆️ ⬇️

2 + 2 * 2 = ::::::

Stay a week before the holidays. So as not to break anything engaged in all garbage.

Remember the kindergarten puzzle “How much is two plus two multiplied by two?”

I decided to find out on sed:

$ sed -f ./1.sed 2+2*2 ;2+;2*;2 ::+::*:: ::+::*: ::+::;::* ::+:::: :::::: 6 




Source itself
 s/[0-9]/;&/gp s/0//g; s/1/:/g; s/2/::/g; s/3/:::/g; s/4/::::/g; s/5/:::::/g; s/6/::::::/g; s/7/:::::::/g; s/8/::::::::/g; s/9/:::::::::/g : ;; s/:;/;::::::::::/gp; t ; s/;//gp s/*:/*/gp : *; s/\(:*\)\*:/\1;\1*/gp; t * s/*//g s/;//gp s/+//gp : -; s/:-:/-/gp; t - s/-$//gp : ? s/::::::::::/;/gp s/;\([0-9]*\)$/;0\1/p s/:::::::::/9/; s/::::::::/8/; s/:::::::/7/; s/::::::/6/; s/:::::/5/; s/::::/4/; s/:::/3/; s/::/2/; s/:/1/ s/;/:/gp t ? s/^$/0/ 




I had enough for the implementation of operations + - *, the move did not reach the division.

Do not look for practical use - it is not here.


')

Source: https://habr.com/ru/post/306356/



All Articles