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: Example. It then returns a 12 - format result for only 200,000 rows.

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.

  • one
    Do not you think that they are stupid in order. can simply drive off the cycle and get the index - Sasuke
  • Welcome to stack overflow in Russian! text information is better to attach as text: a) easier to read; b) can be copied; c) the search works. You can correct the question text by clicking below to edit the question text - aleksandr barakin
  • I read the 2nd, 3rd signs - the last two digits of the year of the entry in the register; what is the minimum year ?? 91 ?? - Sasuke
  • @ Sanitary, not quite in order. There are rules for the formation of OGRN numbers. For example, the second and third digits are always the year of registration, and 6-7 are the tax inspectorate to which the person is assigned. After receiving the list, I want to check the broken links from one site using these great sites, so I try to reduce the number of options whenever possible. - Da Ka
  • @ Sanitary, I cut the sample from 2005 to 2015 - Da Ka

1 answer 1

there is such an option

 var years = ['05','06','07','08','09','10','11','12','13','14','15'] var gos_sign = ['1','5','2','6','7','8','9'] const result = []; for (let z = 0; z < gos_sign.length; z++) { for (let i = 0; i < years.length; i++) { for (let j = 0; j != 999999; j++) { var a = gen_midl(j); var K = a[5]; var last = +K % 11; result.push(`${gos_sign[z]}${years[i]}78${a}${last.toString()[0]}`); } } } function gen_midl(num) { var msx_l = 6; var c_l = num.toString().length; var Y = msx_l - c_l; var r = ''; for (let i = 0; i < Y; i++) { r += '0'; } return r + num.toString(); } console.log(result.length); 

I have a console in chrome, a lot of it turns out about 100kk