It is necessary to create a list of various OGRN numbers for the city of St. Petersburg (78). In total, the OGRN has 13 digits, the logic of which is quite simple. So far I have been picking up only 12 out of 13 digits, since the error goes out precisely in this interval. As a result, the following code came out. But, apparently, I did not take into account something, as a result of which a broken list comes out: 
file = File.new('./file.txt', 'w') one = 1 (5..15).to_a.each do |two_three| if two_three.to_s.length == 1 two_three = "0#{two_three}" end four_five = 78 arr1 = (2..27).to_a arr2 = [0,1,5,6,13,14] arr3 = arr1-arr2 arr3.each do |six_seven| if six_seven.to_s.length == 1 six_seven = "0#{six_seven}" else six_seven = "#{six_seven}" end Array.new(100000) do |index| index + 1 if index.to_s.length == 1 eight_twelve = "0000#{index}" elsif index.to_s.length == 2 eight_twelve = "000#{index}" elsif index.to_s.length == 3 eight_twelve = "00#{index}" elsif index.to_s.length == 4 eight_twelve = "0#{index}" end file.puts "#{one}#{two_three}#{four_five}#{six_seven}#{eight_twelve}" end end end I would be very grateful for the help.