Java, 500 bytes
A couple years late to the party, but I think I've captured the spirit of the question, as it uses no form of looping whatsoever. Takes the first command line argument as an integer (greater than or equal to 1), and prints out its factorial, or terminates with exception in the case of overflow. Since java integers can only hold the factorials of numbers up to 16, it just uses a switch statement with the results hard coded in ;)
public class M{public static void main(String[]args){int n=Integer.parseInt(args[0]);int r;switch(n){case(1):r=1;break;case(2):r=2;break;case(3):r=6;break;case(4):r=24;break;case(5):r=120;break;case(6):r=720;break;case(7):r=5040;break;case(8):r=40320;break;case(9):r=362880;break;case(10):r=3628800;break;case(11):r=39916800;break;case(12):r=479001600;break;case(13):r=1932053504;break;case(14):r=1278945280;break;case(15):r=2004310016;break;case(16):r=2004189184;break;default:r=1/0;}System.out.print(r);}}
EDIT - Saved 7 bytes thanks to NoOneIsHere
class M{public static void main(String[]args){int n=Integer.parseInt(args[0]);int r;switch(n){case(1):r=1;break;case(2):r=2;break;case(3):r=6;break;case(4):r=24;break;case(5):r=120;break;case(6):r=720;break;case(7):r=5040;break;case(8):r=40320;break;case(9):r=362880;break;case(10):r=3628800;break;case(11):r=39916800;break;case(12):r=479001600;break;case(13):r=1932053504;break;case(14):r=1278945280;break;case(15):r=2004310016;break;case(16):r=2004189184;break;default:r=1/0;}System.out.print(r);}}
This eliminates many languages. – ericw31415 – 2016-05-11T20:33:32.510
4im pretty sure this is impossible, u need some sort of looping (built-in or otherwise), unless u let trick looping/recursion. so you have to depend on a built-in looping function? its impossible in many languages.... – Math chiller – 2013-10-23T16:30:02.993
Actually, I've no idea whether it is possible or not, but perhaps someone finds a cool trick using bitwise operators. – ProgramFOX – 2013-10-23T16:32:47.617
i think the answer below is kinda cheating, it does loop just internally – Math chiller – 2013-10-23T16:33:38.717
2Just take a look how numbers are converted to strings, every programming language will loop. (Ok there could be the C equivalent with literal strings) – Johannes Kuhn – 2013-10-23T17:46:58.347
9And by the way: Restricting
eval
changes the rules, invalidates most of the answers, and is just like "ohh, they found an other way to solve this, forbid that too"... – Johannes Kuhn – 2013-10-23T18:53:05.33018-1 for changing the question radically – Doorknob – 2013-10-23T20:54:10.683
3
@ProgramFOX This is impossible (wihtout adding abitiary limitations like 32-bit or defer the loop to the language). The problem you describe here is more or less equivalent to "Find a formula that calculates the factorial". Just look at the Γ-Function. While there are formulas that can calculate
– Johannes Kuhn – 2013-10-24T08:21:12.227n!
, they are too complex and involve eitherΠ
or∫
, which can not be solved without loops/recursion.@JohannesKuhn: May be tcl´s
time
is valid? – sergiol – 2017-08-23T08:22:25.660time
is just a loop. – Johannes Kuhn – 2017-09-02T20:09:10.347