From 7707f7cf59e76186f764264d0c8f4e4f618904f8 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 11 Jun 2017 16:48:12 +0200 Subject: first ruby file --- ruby/lswf.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 ruby/lswf.rb diff --git a/ruby/lswf.rb b/ruby/lswf.rb new file mode 100644 index 0000000..57228ba --- /dev/null +++ b/ruby/lswf.rb @@ -0,0 +1,44 @@ +fib = [] +fib.push 1 +fib.push 1 + +def fibonacci(n, fib) + for i in 2...n do + fib.push fib[i-1] + fib[i-2] + + break if fib[i] > n + end + + return i +end + +File.open('input.txt', 'r') do |fin| + N = fin.gets.to_i +end + +lst = fibonacci(N, fib) + +fib = fib.reverse + +somma = 0 +seq = [] + +for i in 0...fib.length-1 do + potSomma = somma + fib[i] + + if potSomma < N + somma = potSomma + seq << 1 + else + seq << 0 + end +end + +seq << 1 +seq = seq.reverse + +seq.pop if N == 1 || N > 4 + +File.open('output.txt', 'w') do |fout| + seq.each {|c| fout.print c} +end -- cgit v1.2.3-18-g5258