summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-06-11 17:11:14 +0200
committerSanto Cariotti <sancn@live.com>2017-06-11 17:11:14 +0200
commitfc27e8f39720f342b39d86f1ceb7aca8fe1a352d (patch)
treed6b3f7b596d439f3b21a0e7e6d919cdc28f0857d
parent7707f7cf59e76186f764264d0c8f4e4f618904f8 (diff)
fixed some things and added binary-dec
-rw-r--r--python/lswf.py2
-rw-r--r--ruby/conversioneBinariaDec.ru32
-rw-r--r--ruby/lswf.rb2
3 files changed, 34 insertions, 2 deletions
diff --git a/python/lswf.py b/python/lswf.py
index c955631..89230ea 100644
--- a/python/lswf.py
+++ b/python/lswf.py
@@ -14,7 +14,7 @@ def fibonacci(N):
with open('input.txt', 'r') as fin:
N = int(fin.readline())
-lst = fibonacci(N)
+fibonacci(N)
fib.reverse()
print()
diff --git a/ruby/conversioneBinariaDec.ru b/ruby/conversioneBinariaDec.ru
new file mode 100644
index 0000000..c506372
--- /dev/null
+++ b/ruby/conversioneBinariaDec.ru
@@ -0,0 +1,32 @@
+b = 32
+v = Array.new(b, 0)
+
+stringa = gets.to_s
+
+unless stringa.size > b then
+ valVuoto = stringa.size
+end
+
+i = b - valVuoto
+j = 0
+
+loop do
+ v[i] = stringa[j].to_i
+
+ i += 1
+ j += 1
+
+ break unless i < b
+end
+
+i = b - 1
+j = 0
+num = 0
+
+while i > -1 do
+ num += v[i] * (2 ** j)
+ i -= 1
+ j += 1
+end
+
+puts num/2
diff --git a/ruby/lswf.rb b/ruby/lswf.rb
index 57228ba..236847e 100644
--- a/ruby/lswf.rb
+++ b/ruby/lswf.rb
@@ -16,7 +16,7 @@ File.open('input.txt', 'r') do |fin|
N = fin.gets.to_i
end
-lst = fibonacci(N, fib)
+fibonacci(N, fib)
fib = fib.reverse