From ca9720cb41669cb70b2f163da840915254372805 Mon Sep 17 00:00:00 2001 From: Satu Asikainen Date: Sat, 23 Jan 2016 22:37:29 +0200 Subject: [PATCH] =?UTF-8?q?teht=C3=A4v=C3=A4n=2012=201.=20palautus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- koodi.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) mode change 100644 => 100755 koodi.rb diff --git a/koodi.rb b/koodi.rb old mode 100644 new mode 100755 index 932f2b3..b07a8a8 --- a/koodi.rb +++ b/koodi.rb @@ -1 +1,23 @@ # kirjoita koodi tänne +def luokittelu(a) + + koko = a.length - 1 + positiivinen=[] + negatiivinen=[] + pariton=[] + parillinen=[] + for i in 0..koko + positiivinen = a.select{|x| x > 0} + negatiivinen = a.select{|x| x < 0} + pariton = a.select do |x| + x.odd? + end + parillinen = a.reject do |x| + x.odd? + end + + end + summa = a.inject(0){ |tulos, x| tulos + x } + h={:negatiivinen=>negatiivinen.sort, :positiivinen => positiivinen.sort, :parillinen => parillinen.sort,:pariton=> pariton.sort, :summa => summa} + end +