FANDOM


--
-- sum( i=1 to n ) s * 0.7 ^ ( i-1 )
--
 
local p = {}
local commas = require( 'Module:Addcommas' )
 
function p.summation( frame )
 
   local shards = frame.args[1]
   local trips = frame.args[2]
 
   -- just in case
   if type( shards ) == 'string' then
       shards = commas._strip( shards )
       shards = tonumber( shards )
   end
 
   if type( trips ) == 'string' then
       trips = commas._strip( trips )
       trips = tonumber( trips )
   end
 
   -- calling tonumber on a string returns nil
   if not shards or not trips then
       return 'You must pass numbers as arguments'
   end
 
   -- You can't have more than this
   if ( shards > 2147483647 ) then
      shards = 2147483647
   end
 
   -- index for summation
   local i = 1
 
   local sum = shards
   local add
 
   -- past 64, you gain no additional shards, even starting with maximum possible
   while ( i <= trips and i <= 64 ) do
      add = shards * math.pow ( .7, i - 1)
      sum = sum + add
      i = i + 1
   end
 
   sum = math.floor( sum )
   return "You effectively have " .. sum .. " shards"
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.