Begun adding support for a global settings.yml file
This commit is contained in:
90
CT.rb
90
CT.rb
@ -1,48 +1,58 @@
|
|||||||
require "yaml"
|
require "yaml"
|
||||||
require 'erb'
|
require 'erb'
|
||||||
require 'open3'
|
require 'open3'
|
||||||
cli = { 'php' => 'php', 'ruby' => 'ruby', 'javascript'=>'node', 'js'=>'node', 'c' => 'tcc -run'}
|
require 'pp'
|
||||||
|
require 'benchmark'
|
||||||
|
include Benchmark
|
||||||
|
cli = { 'php' => 'php', 'ruby' => 'ruby', 'lua'=> 'lua', 'javascript'=>'node', 'js'=>'node', 'c' => 'tcc -run'}
|
||||||
|
settings = YAML::load_file("settings.yml")
|
||||||
|
|
||||||
problem = YAML::load_file(ARGV[0] + "/desc.yml")
|
problem = YAML::load_file(ARGV[0] + "/desc.yml")
|
||||||
output = ERB.new(IO.read('template.rt'))
|
|
||||||
puts output.result()
|
case ARGV[1]
|
||||||
if(ARGV[1] == 'test')
|
when 'test'
|
||||||
if(problem['solutions'])
|
if(problem['solutions'])
|
||||||
problem['solutions'].each do |sol|
|
problem['solutions'].each do |sol|
|
||||||
if(cli[sol[1]['language']])
|
if(cli[sol[1]['language']])
|
||||||
parameter = (sol[1]['parameters']) ? " " + sol[1]['parameters'] : ""
|
puts "--------------\n|"+sol[0]+"\n--------------"
|
||||||
stdin, stdout, stderr = Open3.popen3(cli[sol[1]['language']] + " "+ARGV[0]+"/"+sol[0] + parameter)
|
puts sol[1]['desc']
|
||||||
puts sol[0]+": " +stdout.readlines[0]
|
parameter = (sol[1]['parameters']) ? " " + sol[1]['parameters'] : ""
|
||||||
#Open3#popen3(cli[sol[1]['language']] + " "+ARGV[0]+"/"+sol[0])
|
stdin, stdout, stderr = Open3.popen3(cli[sol[1]['language']] + " "+ARGV[0]+"/"+sol[0] + parameter)
|
||||||
|
puts "Result: " + stdout.readlines[0]
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
puts "No solutions for said problem"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
when 'table'
|
||||||
|
|
||||||
|
require 'terminal-table'
|
||||||
|
files = Dir[ARGV[0]+"/**/*/desc.yml"]
|
||||||
|
files.sort
|
||||||
|
entry = []
|
||||||
|
files.each do |file|
|
||||||
|
yaml = YAML::load_file(file)
|
||||||
|
nested = file.split('/')
|
||||||
|
count = 0
|
||||||
|
if( yaml['solution'] and yaml['solutions'])
|
||||||
|
yaml['solutions'].each do |sol|
|
||||||
|
count += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
entry << {'title'=>yaml['title'],'code'=>nested[-2].to_s,'solved'=>count}
|
||||||
|
end
|
||||||
|
|
||||||
|
rows = []
|
||||||
|
entry.each do |e|
|
||||||
|
solvedstring = (e['solved'] == 0) ? "No" : "Yes("+e['solved'].to_s+")"
|
||||||
|
row = [e['code'],e['title'],solvedstring]
|
||||||
|
rows << row
|
||||||
|
end
|
||||||
|
table = Terminal::Table.new(:headings => ['Code','Title','Solved'],:rows => rows)
|
||||||
|
puts table
|
||||||
else
|
else
|
||||||
puts "No solutions for said problem"
|
output = ERB.new(IO.read('template.rt'))
|
||||||
end
|
puts output.result()
|
||||||
end
|
|
||||||
|
|
||||||
if(ARGV[1] == 'table')
|
|
||||||
require 'terminal-table'
|
|
||||||
files = Dir[ARGV[0]+"/**/*/desc.yml"]
|
|
||||||
files.sort
|
|
||||||
entry = []
|
|
||||||
files.each do |file|
|
|
||||||
yaml = YAML::load_file(file)
|
|
||||||
nested = file.split('/')
|
|
||||||
count = 0
|
|
||||||
if( yaml['solution'] and yaml['solutions'])
|
|
||||||
yaml['solutions'].each do |sol|
|
|
||||||
count += 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
entry << {'title'=>yaml['title'],'code'=>nested[-2].to_s,'solved'=>count}
|
|
||||||
end
|
|
||||||
|
|
||||||
rows = []
|
|
||||||
entry.each do |e|
|
|
||||||
solvedstring = (e['solved'] == 0) ? "No" : "Yes("+e['solved'].to_s+")"
|
|
||||||
row = [e['code'],e['title'],solvedstring]
|
|
||||||
rows << row
|
|
||||||
end
|
|
||||||
table = Terminal::Table.new(:headings => ['Code','Title','Solved'],:rows => rows)
|
|
||||||
puts table
|
|
||||||
end
|
end
|
||||||
|
@ -15,3 +15,6 @@ solutions:
|
|||||||
solve.rb:
|
solve.rb:
|
||||||
desc: Basic solution in Ruby
|
desc: Basic solution in Ruby
|
||||||
language: ruby
|
language: ruby
|
||||||
|
solve.js:
|
||||||
|
desc: Basic solution for NodeJS
|
||||||
|
language: js
|
11
ProjectEuler/005/solve.js
Normal file
11
ProjectEuler/005/solve.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
for(i=20;true;i+=20) {
|
||||||
|
div = 19;
|
||||||
|
|
||||||
|
while(!(i % div)) {
|
||||||
|
div--;
|
||||||
|
if(div == 0) {
|
||||||
|
console.log( i );
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,3 +22,6 @@ solutions:
|
|||||||
solve.c:
|
solve.c:
|
||||||
desc: ANSI C solution (Tested with TCC)
|
desc: ANSI C solution (Tested with TCC)
|
||||||
language: c
|
language: c
|
||||||
|
solve.js:
|
||||||
|
desc: Javascript solution for NodeJS
|
||||||
|
language: javascript
|
9
ProjectEuler/006/solve.js
Normal file
9
ProjectEuler/006/solve.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
square = 0;
|
||||||
|
sum = 0;
|
||||||
|
for(num=1;num<101;num++) {
|
||||||
|
square += Math.pow(num,2);
|
||||||
|
sum += num;
|
||||||
|
|
||||||
|
}
|
||||||
|
console.log( Math.pow(sum,2) - square);
|
||||||
|
|
16
settings.yml
Normal file
16
settings.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
languages:
|
||||||
|
javascript:
|
||||||
|
command: node
|
||||||
|
ext: [js,javascript]
|
||||||
|
php:
|
||||||
|
command: php
|
||||||
|
ext: [php]
|
||||||
|
ruby:
|
||||||
|
command: ruby
|
||||||
|
ext: [ruby,rb]
|
||||||
|
tcc:
|
||||||
|
command: tcc -run
|
||||||
|
ext: [c]
|
||||||
|
lua:
|
||||||
|
command: lua
|
||||||
|
ext: [lua]
|
Reference in New Issue
Block a user