Skip to main content
Because who needs brackets???
Source Link
br3nt
  • 161
  • 4

Ruby: 4139 bytes

->(s>s,m){(0...s*s).reduce(0){|a,b|a+m**b}}

Test:

f = ->(s>s,m){(0...s*s).reduce(0){|a,b|a+m**b}}

f[8,2]   # 18446744073709551615
f[3,6]   # 2015539
f[7,1.5] # 850161998.2853994
f[5,-3]  # 211822152361
f[256,1] # 65536
f[2,2]   # 15
f[2,-2]  # -5
f[1,1]   # 1

Ruby: 41 bytes

->(s,m){(0...s*s).reduce(0){|a,b|a+m**b}}

Test:

f = ->(s,m){(0...s*s).reduce(0){|a,b|a+m**b}}

f[8,2]   # 18446744073709551615
f[3,6]   # 2015539
f[7,1.5] # 850161998.2853994
f[5,-3]  # 211822152361
f[256,1] # 65536
f[2,2]   # 15
f[2,-2]  # -5
f[1,1]   # 1

Ruby: 39 bytes

->s,m{(0...s*s).reduce(0){|a,b|a+m**b}}

Test:

f = ->s,m{(0...s*s).reduce(0){|a,b|a+m**b}}

f[8,2]   # 18446744073709551615
f[3,6]   # 2015539
f[7,1.5] # 850161998.2853994
f[5,-3]  # 211822152361
f[256,1] # 65536
f[2,2]   # 15
f[2,-2]  # -5
f[1,1]   # 1
As suggested by @user2251284 - with sight modification to fix an off by 1 error
Source Link
br3nt
  • 161
  • 4

Ruby: 4341 bytes

->(s,m){(0...s*s).map{|v|m**v}.injectreduce(&:+0){|a,b|a+m**b}}

Test:

f = ->(s,m){(0...s*s).map{|v|m**v}.injectreduce(&:+0){|a,b|a+m**b}}

f[8,2]   # 18446744073709551615
f[3,6]   # 2015539
f[7,1.5] # 850161998.2853994
f[5,-3]  # 211822152361
f[256,1] # 65536
f[2,2]   # 15
f[2,-2]  # -5
f[1,1]   # 1

Ruby: 43 bytes

->(s,m){(0...s*s).map{|v|m**v}.inject(&:+)}

Test:

f = ->(s,m){(0...s*s).map{|v|m**v}.inject(&:+)}

f[8,2]   # 18446744073709551615
f[3,6]   # 2015539
f[7,1.5] # 850161998.2853994
f[5,-3]  # 211822152361
f[256,1] # 65536
f[2,2]   # 15
f[2,-2]  # -5

Ruby: 41 bytes

->(s,m){(0...s*s).reduce(0){|a,b|a+m**b}}

Test:

f = ->(s,m){(0...s*s).reduce(0){|a,b|a+m**b}}

f[8,2]   # 18446744073709551615
f[3,6]   # 2015539
f[7,1.5] # 850161998.2853994
f[5,-3]  # 211822152361
f[256,1] # 65536
f[2,2]   # 15
f[2,-2]  # -5
f[1,1]   # 1
Replace rails' `sum` method with ruby core method `inject` and `+`
Source Link
br3nt
  • 161
  • 4

Ruby: 3543 bytes

->(s,m){(0...s*s).map{|v|m**v}.suminject(&:+)}

Test:

f = ->(s,m){(0...s*s).map{|v|m**v}.suminject(&:+)}

f[8,2]   # 18446744073709551615
f[3,6]   # 2015539
f[7,1.5] # 850161998.2853994
f[5,-3]  # 211822152361
f[256,1] # 65536
f[2,2]   # 15
f[2,-2]  # -5

Ruby: 35 bytes

->(s,m){(0...s*s).map{|v|m**v}.sum}

Test:

f = ->(s,m){(0...s*s).map{|v|m**v}.sum}

f[8,2]   # 18446744073709551615
f[3,6]   # 2015539
f[7,1.5] # 850161998.2853994
f[5,-3]  # 211822152361
f[256,1] # 65536
f[2,2]   # 15
f[2,-2]  # -5

Ruby: 43 bytes

->(s,m){(0...s*s).map{|v|m**v}.inject(&:+)}

Test:

f = ->(s,m){(0...s*s).map{|v|m**v}.inject(&:+)}

f[8,2]   # 18446744073709551615
f[3,6]   # 2015539
f[7,1.5] # 850161998.2853994
f[5,-3]  # 211822152361
f[256,1] # 65536
f[2,2]   # 15
f[2,-2]  # -5
Source Link
br3nt
  • 161
  • 4
Loading