Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In bash

  $ echo "print((-80538738812075974)^3 + 80435758145817515^3 + 12602123297335631^3)" | sed "s/\^/**/g" | python -
  42


You're just using python, using bc is more bashy:

    $ echo '(-80538738812075974)^3 + 80435758145817515^3 + 12602123297335631^3' | bc
    42


Without shelling out:

  $ echo $(((-80538738812075974)**3 + 80435758145817515**3 + 12602123297335631**3))
  42


In calc:

$ calc

calc 2.12.4.1

> (-80538738812075974)^3 + 80435758145817515^3 + 12602123297335631^3

        42
>

Literally pasted off the web page and verified in a couple of seconds.


One more proof that you can do everything in bash.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: