Created
June 23, 2013 05:59
-
-
Save delonnewman/5843976 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let funnysums n = | |
seq { 1 .. n } |> Seq.map (fun i -> seq { 0 .. i } |> Seq.reduce(+)) | |
[<EntryPointAttribute>] | |
let main args = | |
let sums = funnysums(Int32.Parse(args.[0])) | |
printfn "%A" sums | |
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment | |
funnysum :: Int -> [Int] | |
funnysum n = map (\x -> sum [0..x]) [0..n] | |
main = do | |
argv <- getArgs | |
let num = (read (head argv))::Int | |
putStrLn $ show (funnysum num) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function funnysums(n) { | |
var i = 0; | |
var sums = []; | |
for (; i <= n; i++) { | |
var j = 0; | |
var sum = 0; | |
for (; j <= i; j++) { | |
sum += j; | |
} | |
sums.push(sum); | |
} | |
return sums; | |
} | |
console.log(funnysums(30)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl6 | |
sub MAIN($n) { | |
(0..$n).map({ [+] 0..$_ }).say | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
def funnysums(n): | |
return map(lambda i: sum(range(1, i+1)), range(0, n+1)) | |
if __name__ == '__main__': | |
n = int(sys.argv[1]) | |
print funnysums(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FunnySum | |
module Recursive | |
def sum n | |
if n == 0 then 0 | |
else | |
n + sum(n - 1) | |
end | |
end | |
def sums n | |
if n == 0 then [ 0 ] | |
else | |
sum(n) + sums(n - 1) | |
end | |
end | |
end | |
def sums n | |
(0..n).map { |i| (0..i).reduce(:+) } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object FunnySum { | |
def funnysums(n : Int) : List[Int] = { | |
List.range(1, n+1).map(List.range(0, _).reduceLeft[Int](_+_)) | |
} | |
def main(args : Array[String]) : Unit = { | |
println(funnysums(args(0).toInt)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "rb-funny-sum.h" | |
static VALUE rb_funny_sum(VALUE mod, VALUE n) { | |
long sum = funny_sum(NUM2INT(n)); | |
return INT2NUM(sum); | |
} | |
static VALUE rb_funny_sums(VALUE mod, VALUE n) { | |
VALUE sums = rb_ary_new(); | |
long i; | |
long num = NUM2INT(n); | |
for (i = 0; i <= num; i++) { | |
rb_ary_store(sums, i, INT2NUM(funny_sum(i))); | |
} | |
return sums; | |
} | |
void Init_FunnySum() { | |
mFunnySum = rb_define_module("FunnySum"); | |
rb_define_module_function(mFunnySum, "sum", rb_funny_sum, 1); | |
rb_define_module_function(mFunnySum, "sums", rb_funny_sums, 1); | |
rb_define_global_function("funnysum", rb_funny_sum, 1); | |
rb_define_global_function("funnysums", rb_funny_sums, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment