From 726c15fcd2ed08c70558198cc154ab2fcc25d931 Mon Sep 17 00:00:00 2001 From: Joonatan Vuorela Date: Wed, 20 Jan 2016 13:47:23 +0200 Subject: [PATCH] =?UTF-8?q?teht=C3=A4v=C3=A4=2012?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- koodi.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) mode change 100644 => 100755 koodi.rb diff --git a/koodi.rb b/koodi.rb old mode 100644 new mode 100755 index 932f2b3..6aabde2 --- a/koodi.rb +++ b/koodi.rb @@ -1 +1,24 @@ -# kirjoita koodi tänne +def luokittelu(taulukko) +hash = {negatiivinen: [], positiivinen: [], parillinen: [], pariton: [], summa: 0} +taulukko.each do |luku| + +if (luku < 0) +hash[:negatiivinen].push(luku) +end +if (luku > 0) +hash[:positiivinen].push(luku) +end +if (luku%2 == 0) +hash[:parillinen].push(luku) +end +if (luku%2 != 0) +hash[:pariton].push(luku) +end +hash[:summa] += luku +end + +hash.each_key do |key| +hash[key].sort! if hash[key].kind_of? Array +end +return hash +end \ No newline at end of file