Begun adding support for a global settings.yml file

This commit is contained in:
FuryFire 2011-04-12 14:12:02 +02:00
parent b25e8b7c11
commit 80dbb818a8
7 changed files with 94 additions and 41 deletions

26
CT.rb

@ -1,26 +1,33 @@
require "yaml"
require 'erb'
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")
output = ERB.new(IO.read('template.rt'))
puts output.result()
if(ARGV[1] == 'test')
case ARGV[1]
when 'test'
if(problem['solutions'])
problem['solutions'].each do |sol|
if(cli[sol[1]['language']])
puts "--------------\n|"+sol[0]+"\n--------------"
puts sol[1]['desc']
parameter = (sol[1]['parameters']) ? " " + sol[1]['parameters'] : ""
stdin, stdout, stderr = Open3.popen3(cli[sol[1]['language']] + " "+ARGV[0]+"/"+sol[0] + parameter)
puts sol[0]+": " +stdout.readlines[0]
#Open3#popen3(cli[sol[1]['language']] + " "+ARGV[0]+"/"+sol[0])
puts "Result: " + stdout.readlines[0]
end
end
else
puts "No solutions for said problem"
end
end
if(ARGV[1] == 'table')
when 'table'
require 'terminal-table'
files = Dir[ARGV[0]+"/**/*/desc.yml"]
files.sort
@ -45,4 +52,7 @@ if(ARGV[1] == 'table')
end
table = Terminal::Table.new(:headings => ['Code','Title','Solved'],:rows => rows)
puts table
else
output = ERB.new(IO.read('template.rt'))
puts output.result()
end

@ -15,3 +15,6 @@ solutions:
solve.rb:
desc: Basic solution in Ruby
language: ruby
solve.js:
desc: Basic solution for NodeJS
language: js

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:
desc: ANSI C solution (Tested with TCC)
language: c
solve.js:
desc: Javascript solution for NodeJS
language: javascript

@ -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);

1
ct.bat

@ -1 +1,2 @@
@ECHO OFF
ruby CT.rb %1 %2

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]