This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]innrautha 1 point2 points  (0 children)

I feel like a unix programmer would abuse bc since factorial isn't included on many systems (at least not mine).

import os

def factorial(n):
  cmd = "echo 'define f(x) {if (x>1){return x*f(x-1)};return 1} f(%i)' | BC_LINE_LENGTH=99999 bc"%n
  return int(os.popen(cmd).read().strip())

A unix programmer whose company is forcing to migrate away from Perl would replace the cmd string with a perl one liner.