From 4291ccdc3ae3d0b3e40a7c15212f53a2c1a6eb0d Mon Sep 17 00:00:00 2001 From: Snezhnyy Date: Sun, 4 Mar 2018 00:57:48 +0300 Subject: [PATCH 1/2] changed the names of variables Homework 1: The Magic Triangle Pascals triangle with fix(i)es --- 2018/AnatoliDobshikov/1/pascals_triangle.rb | 90 +++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 2018/AnatoliDobshikov/1/pascals_triangle.rb diff --git a/2018/AnatoliDobshikov/1/pascals_triangle.rb b/2018/AnatoliDobshikov/1/pascals_triangle.rb new file mode 100644 index 000000000..fc917c63c --- /dev/null +++ b/2018/AnatoliDobshikov/1/pascals_triangle.rb @@ -0,0 +1,90 @@ +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> 987cd1c... changed the names of variables +# Program draws pascal's triangle with the specified depth in the console +# values input +print 'Input tree depth: ' +tree_depth = gets.chomp.to_i +print 'Input base number: ' +base_number = gets.chomp.to_i +# checking values +if tree_depth <= 0 || base_number <= 0 + puts 'Invalid value. Try to type positive integer.' +<<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> 987cd1c... changed the names of variables + exit +end +# tree create +NUM_LENGTH = 4 # the maximal length in the triangle +coef = [base_number] +<<<<<<< HEAD +<<<<<<< HEAD +cols = `/usr/bin/tput cols`.chomp.to_i +<<<<<<< HEAD +<<<<<<< HEAD +spaces = ' ' * (tree_depth / FOUR > 0 ? tree_depth / 4 : 1) +======= +spaces = ' ' * (tree_depth / FOUR > 0 ? tree_depth / FOUR : 1) +>>>>>>> 987cd1c... changed the names of variables +======= +======= +console_cols = `/usr/bin/tput cols`.chomp.to_i +>>>>>>> a882e80... Pascals triangle with fix(i)es +spaces = ' ' * (tree_depth / NUM_LENGTH > 0 ? tree_depth / NUM_LENGTH : 1) +>>>>>>> 9ebe98e... New understanging of the names of the variables! +(0...tree_depth).each do |level| +======= +console_cols = `/usr/bin/tput cols`.chomp.to_i - 4 # fix trailing blank line +spaces = ' ' * (tree_depth / NUM_LENGTH > 0 ? tree_depth / NUM_LENGTH : 1) +tree_depth.times do |level| +>>>>>>> 74ee23b... Pascals triangle with fix(i)es + printf('%03d:', level) + puts coef.join(spaces).center(console_cols) + coef.push(0) + (level + 1).downto(1) do |column| + coef[column] += coef[column - 1] + end +end +<<<<<<< HEAD + +<<<<<<< HEAD +======= +#Program draws pascal's triangle with the specified depth in the console +#values input +print "Input tree depth: "; +======= +# Program draws pascal's triangle with the specified depth in the console +# values input +print 'Input tree depth: ' +>>>>>>> d239144... fix styling issues +tree_depth = gets.chomp.to_i +print 'Input base number: ' +base_number = gets.chomp.to_i +# checking values +if tree_depth <= 0 || base_number <= 0 + puts 'Invalid value. Try to type integer.' +======= +>>>>>>> 42628a3... some optimization + exit +end +# tree create +coef = [base_number] +cols = `/usr/bin/tput cols`.chomp.to_i +spaces = ' ' * (tree_depth / 4 > 0 ? tree_depth / 4 : 1) +0.upto(tree_depth - 1) do |i| + printf('%03d:', i) + puts coef.join(spaces).center(cols) + coef.push(0) + (i + 1).downto(1) do |j| + coef[j] += coef[j - 1] + end +end +>>>>>>> 19cbc15... homework 1 +======= +>>>>>>> 987cd1c... changed the names of variables +======= +>>>>>>> f1acbcc... deleted trailing blank line From 74865cf1a4521b4532d7b991574b39274ed3bb5d Mon Sep 17 00:00:00 2001 From: Snezhnyy Date: Wed, 28 Mar 2018 00:02:00 +0300 Subject: [PATCH 2/2] I hope it will work --- 2018/AnatoliDobshikov/1/pascals_triangle.rb | 66 --------------------- 1 file changed, 66 deletions(-) diff --git a/2018/AnatoliDobshikov/1/pascals_triangle.rb b/2018/AnatoliDobshikov/1/pascals_triangle.rb index fc917c63c..1019541c8 100644 --- a/2018/AnatoliDobshikov/1/pascals_triangle.rb +++ b/2018/AnatoliDobshikov/1/pascals_triangle.rb @@ -1,8 +1,3 @@ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 987cd1c... changed the names of variables # Program draws pascal's triangle with the specified depth in the console # values input print 'Input tree depth: ' @@ -12,36 +7,14 @@ # checking values if tree_depth <= 0 || base_number <= 0 puts 'Invalid value. Try to type positive integer.' -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 987cd1c... changed the names of variables exit end # tree create NUM_LENGTH = 4 # the maximal length in the triangle coef = [base_number] -<<<<<<< HEAD -<<<<<<< HEAD -cols = `/usr/bin/tput cols`.chomp.to_i -<<<<<<< HEAD -<<<<<<< HEAD -spaces = ' ' * (tree_depth / FOUR > 0 ? tree_depth / 4 : 1) -======= -spaces = ' ' * (tree_depth / FOUR > 0 ? tree_depth / FOUR : 1) ->>>>>>> 987cd1c... changed the names of variables -======= -======= -console_cols = `/usr/bin/tput cols`.chomp.to_i ->>>>>>> a882e80... Pascals triangle with fix(i)es -spaces = ' ' * (tree_depth / NUM_LENGTH > 0 ? tree_depth / NUM_LENGTH : 1) ->>>>>>> 9ebe98e... New understanging of the names of the variables! -(0...tree_depth).each do |level| -======= console_cols = `/usr/bin/tput cols`.chomp.to_i - 4 # fix trailing blank line spaces = ' ' * (tree_depth / NUM_LENGTH > 0 ? tree_depth / NUM_LENGTH : 1) tree_depth.times do |level| ->>>>>>> 74ee23b... Pascals triangle with fix(i)es printf('%03d:', level) puts coef.join(spaces).center(console_cols) coef.push(0) @@ -49,42 +22,3 @@ coef[column] += coef[column - 1] end end -<<<<<<< HEAD - -<<<<<<< HEAD -======= -#Program draws pascal's triangle with the specified depth in the console -#values input -print "Input tree depth: "; -======= -# Program draws pascal's triangle with the specified depth in the console -# values input -print 'Input tree depth: ' ->>>>>>> d239144... fix styling issues -tree_depth = gets.chomp.to_i -print 'Input base number: ' -base_number = gets.chomp.to_i -# checking values -if tree_depth <= 0 || base_number <= 0 - puts 'Invalid value. Try to type integer.' -======= ->>>>>>> 42628a3... some optimization - exit -end -# tree create -coef = [base_number] -cols = `/usr/bin/tput cols`.chomp.to_i -spaces = ' ' * (tree_depth / 4 > 0 ? tree_depth / 4 : 1) -0.upto(tree_depth - 1) do |i| - printf('%03d:', i) - puts coef.join(spaces).center(cols) - coef.push(0) - (i + 1).downto(1) do |j| - coef[j] += coef[j - 1] - end -end ->>>>>>> 19cbc15... homework 1 -======= ->>>>>>> 987cd1c... changed the names of variables -======= ->>>>>>> f1acbcc... deleted trailing blank line