5 kyu

Going to zero or to infinity?

77 of 6,092g964

Description:

Consider the following numbers (where n! is factorial(n)):

u1 = (1 / 1!) * (1!)
u2 = (1 / 2!) * (1! + 2!)
u3 = (1 / 3!) * (1! + 2! + 3!)
...
un = (1 / n!) * (1! + 2! + 3! + ... + n!)

Which will win: 1 / n! or (1! + 2! + 3! + ... + n!)?

Are these numbers going to 0 because of 1/n! or to infinity due to the sum of factorials or to another number?

Task

Calculate (1 / n!) * (1! + 2! + 3! + ... + n!) for a given n, where n is an integer greater or equal to 1.

Your result should be within 10^-6 of the expected one.

Remark

Keep in mind that factorials grow rather rapidly, and you need to handle large inputs.

Hint

You could try to simplify the expression.

Mathematics
Algorithms

More By Author:

Check out these other kata created by g964

Stats:

CreatedJul 12, 2015
PublishedJul 12, 2015
Warriors Trained27557
Total Skips8138
Total Code Submissions117824
Total Times Completed6092
Ruby Completions133
Python Completions1552
JavaScript Completions837
Haskell Completions170
C# Completions381
Java Completions789
CoffeeScript Completions17
Clojure Completions54
TypeScript Completions207
C++ Completions643
PHP Completions156
Crystal Completions11
F# Completions44
C Completions489
Rust Completions267
Swift Completions93
Go Completions214
R Completions56
Shell Completions20
OCaml Completions30
Fortran Completions18
Elixir Completions43
Julia Completions39
Scala Completions77
PowerShell Completions12
Nim Completions9
Reason Completions5
Racket Completions22
Forth Completions13
Kotlin Completions104
Prolog Completions12
Haxe Completions9
COBOL Completions6
Elm Completions4
Erlang Completions9
NASM Completions9
D Completions4
Total Stars592
% of votes with a positive feedback rating85% of 857
Total "Very Satisfied" Votes642
Total "Somewhat Satisfied" Votes165
Total "Not Satisfied" Votes50
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • anter69 Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • FArekkusu Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • depial Avatar
Ad