Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What language is this?
#15
(02-20-2010, 10:39 PM)uber1337 Wrote:
Code:
reduce(lambda x,y : x+y, [x for x in xrange(1000) if x % 3 == 0 or x % 5 == 0])

We can do it like that too, by packing everything together.
Code:
x=0;(0..1000).each{|f|(f%3==0||f%5==0)?x+=f : nil}

or we could do this:

Code:
#!/usr/bin/env ruby
def calculate()
  tmp = 0
  (0..1000).each do |number|
    if (number % 3 == 0 || number % 5 == 0) then
      tmp += number
    end
  end
puts number
end
calculate()

-------------------------------------------------------------------------------------

(02-20-2010, 10:39 PM)uber1337 Wrote: I honestly think '*' is pretty descriptive considering it is the multiplication operator in just about every language I can think of( besides Ruby)

Code:
irb(main):001:0>  5 * 5
=> 25
irb(main):009:0> print " a " * 3
a  a  a
=> nil

You can multiply using "*" in Ruby

------------------------------------------------------------------

Good code is code that you can read.
Or maybe I'm just retarded and my code doesn't work. :O
Reply


Messages In This Thread
What language is this? - by eXPerience™ - 02-20-2010, 01:33 PM
RE: What language is this? - by Jordan L. - 02-20-2010, 04:26 PM
RE: What language is this? - by Omniscient - 02-20-2010, 04:57 PM
RE: What language is this? - by Canoris - 02-20-2010, 06:06 PM
RE: What language is this? - by Omniscient - 02-20-2010, 06:31 PM
RE: What language is this? - by Jordan L. - 02-20-2010, 06:43 PM
RE: What language is this? - by Zomaian - 02-20-2010, 07:00 PM
RE: What language is this? - by Omniscient - 02-20-2010, 07:11 PM
RE: What language is this? - by Zomaian - 02-20-2010, 08:08 PM
RE: What language is this? - by eXPerience™ - 02-20-2010, 07:21 PM
RE: What language is this? - by uber1337 - 02-20-2010, 09:48 PM
RE: What language is this? - by Ph4ge - 03-03-2010, 08:43 PM
RE: What language is this? - by Zomaian - 02-20-2010, 10:25 PM
RE: What language is this? - by uber1337 - 02-20-2010, 10:39 PM
RE: What language is this? - by Wolskie - 02-23-2010, 03:16 AM
RE: What language is this? - by eXPerience™ - 02-21-2010, 10:38 AM
RE: What language is this? - by uber1337 - 02-23-2010, 06:54 PM
RE: What language is this? - by Wolskie - 02-23-2010, 09:54 PM
RE: What language is this? - by Canoris - 02-26-2010, 09:13 PM
RE: What language is this? - by uber1337 - 02-24-2010, 12:22 PM
RE: What language is this? - by uber1337 - 02-26-2010, 10:05 PM
RE: What language is this? - by Wolskie - 02-26-2010, 11:13 PM
RE: What language is this? - by uber1337 - 02-27-2010, 08:27 AM
RE: What language is this? - by Wolskie - 02-28-2010, 12:09 AM
RE: What language is this? - by uber1337 - 02-28-2010, 08:45 AM
RE: What language is this? - by Wolskie - 03-04-2010, 02:17 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)