| | #!/usr/bin/env ruby |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | 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) |
| | |
| | highest_program_id = program_ids.max |
| | |
| | |
| | image_width = 1000 |
| | image_height = (highest_program_id / 1000) + 1 |
| | |
| | |
| | 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) |
| |
|
| |
|