File size: 2,008 Bytes
d5bfab8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env ruby

=begin

This script generates an image with an overview of what files already exist and
what is yet to be mined.

This script traverses all the programs inside the "loda-programs/oeis" dir.

For every program that exist, a black pixel is plotted.
White pixels when there exist no program.

The image width is always 1000 pixels.
The image height varies depending on how many programs that have been mined.
The top-left pixel correspond to A000000.
The top-right pixel correspond to A000999.

=end

require 'set'
require_relative 'config'

LODA_PROGRAMS_OEIS = Config.instance.loda_programs_oeis

def obtain_program_ids(rootdir)
    paths = Dir.glob(File.join("**", "*.asm"), base: rootdir)

    program_ids = Set.new
    paths.map do |path|
        path =~ /0*(\d+)[.]asm/
        program_id = $1.to_i
        if program_id == 0
            puts "Mismatch for #{filename}"
            next
        end
        program_ids.add(program_id)
    end
    program_ids
end

def generate_image(program_ids)
    # p program_ids.count
    highest_program_id = program_ids.max
    # p highest_program_id
    
    image_width = 1000
    image_height = (highest_program_id / 1000) + 1
    # p image_height
    
    rows = []
    rows << "P1"
    rows << "\# loda_file_status_image.pbm"
    rows << "#{image_width} #{image_height}"
    image_height.times do |y|
        row = []
        image_width.times do |x|
            offset = y * image_width + x
            program_exist = program_ids.include?(offset)
            if program_exist
               row << 1
            else 
               row << 0
            end
        end
        rows << row.join(' ')
    end
    filename = "data/loda_file_status_image.pbm"
    content = rows.join("\n")
    IO.write(filename, content)
    puts "generated file: '#{filename}'  filesize: #{content.bytes.count}"
    puts "number of black pixels: #{program_ids.count}" 
end

program_ids = obtain_program_ids(LODA_PROGRAMS_OEIS)
generate_image(program_ids)