Added a few lua solutions - Updated the CT script to include additional parameters
This commit is contained in:
19
CT.rb
19
CT.rb
@ -1,9 +1,24 @@
|
|||||||
require "yaml"
|
require "yaml"
|
||||||
require 'erb'
|
require 'erb'
|
||||||
|
require 'open3'
|
||||||
|
cli = { 'php' => 'php', 'ruby' => 'ruby', 'javascript'=>'node', 'js'=>'node', 'c' => 'tcc -run'}
|
||||||
problem = YAML::load_file(ARGV[0] + "/desc.yml")
|
problem = YAML::load_file(ARGV[0] + "/desc.yml")
|
||||||
output = ERB.new(IO.read('template.rt'))
|
output = ERB.new(IO.read('template.rt'))
|
||||||
puts output.result()
|
puts output.result()
|
||||||
|
if(ARGV[1] == 'test')
|
||||||
|
if(problem['solutions'])
|
||||||
|
problem['solutions'].each do |sol|
|
||||||
|
if(cli[sol[1]['language']])
|
||||||
|
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])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "No solutions for said problem"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if(ARGV[1] == 'table')
|
if(ARGV[1] == 'table')
|
||||||
require 'terminal-table'
|
require 'terminal-table'
|
||||||
@ -30,4 +45,4 @@ if(ARGV[1] == 'table')
|
|||||||
end
|
end
|
||||||
table = Terminal::Table.new(:headings => ['Code','Title','Solved'],:rows => rows)
|
table = Terminal::Table.new(:headings => ['Code','Title','Solved'],:rows => rows)
|
||||||
puts table
|
puts table
|
||||||
end
|
end
|
||||||
|
@ -21,3 +21,6 @@ solutions:
|
|||||||
solve.js:
|
solve.js:
|
||||||
desc: NodeJS solution
|
desc: NodeJS solution
|
||||||
language: javascript
|
language: javascript
|
||||||
|
solve.lua:
|
||||||
|
desc: Basic solution
|
||||||
|
language: lua
|
||||||
|
7
ProjectEuler/001/solve.lua
Normal file
7
ProjectEuler/001/solve.lua
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
sum = 0
|
||||||
|
for i=1,999 do
|
||||||
|
if i % 3 == 0 or i % 5 == 0 then
|
||||||
|
sum = sum + i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
print(sum)
|
@ -21,4 +21,7 @@ solutions:
|
|||||||
language: c
|
language: c
|
||||||
solve.js:
|
solve.js:
|
||||||
desc: NodeJS solution
|
desc: NodeJS solution
|
||||||
language: javascript
|
language: javascript
|
||||||
|
solve.lua:
|
||||||
|
desc: Basic solution
|
||||||
|
language: lua
|
@ -5,7 +5,7 @@ fib = new Array( 1, 2, 3 );
|
|||||||
fib[2] = fib[0] + fib[1];
|
fib[2] = fib[0] + fib[1];
|
||||||
if(fib[2] % 2 == 0)
|
if(fib[2] % 2 == 0)
|
||||||
sum += fib[2];
|
sum += fib[2];
|
||||||
fib[0] = fib[1];
|
fib[0] = fib[1];
|
||||||
fib[1] = fib[2];
|
fib[1] = fib[2];
|
||||||
}
|
}
|
||||||
console.log(sum );
|
console.log(sum );
|
||||||
|
11
ProjectEuler/002/solve.lua
Normal file
11
ProjectEuler/002/solve.lua
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
sum = 2
|
||||||
|
fib = {1, 2, 3}
|
||||||
|
while fib[2] < 4000000 do
|
||||||
|
fib[3] = fib[1] + fib[2]
|
||||||
|
if(fib[3] % 2 == 0) then
|
||||||
|
sum = sum + fib[3]
|
||||||
|
end
|
||||||
|
fib[1] = fib[2]
|
||||||
|
fib[2] = fib[3]
|
||||||
|
end
|
||||||
|
print (sum )
|
@ -1,10 +1,13 @@
|
|||||||
max = 0;
|
i = 0
|
||||||
(100..1000).each do |num1|
|
while (true)
|
||||||
(100..1000).each do |num2|
|
i = i + 20
|
||||||
sum = num1 * num2
|
div = 19
|
||||||
if( sum > max and sum.to_s.reverse == sum.to_s)
|
|
||||||
max = sum
|
while((i % div) == 0)
|
||||||
|
div = div - 1
|
||||||
|
if(div == 0) then
|
||||||
|
puts i
|
||||||
|
exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
print max
|
|
@ -19,6 +19,6 @@ solutions:
|
|||||||
solve.rb:
|
solve.rb:
|
||||||
desc: Basic Ruby solution
|
desc: Basic Ruby solution
|
||||||
language: ruby
|
language: ruby
|
||||||
solve.rb:
|
solve.c:
|
||||||
desc: ANSI C solution (Tested with TCC)
|
desc: ANSI C solution (Tested with TCC)
|
||||||
language: c
|
language: c
|
@ -11,6 +11,8 @@ solutions:
|
|||||||
solve.php:
|
solve.php:
|
||||||
desc: Expects the haystack as stdin with optional newlines
|
desc: Expects the haystack as stdin with optional newlines
|
||||||
language: php
|
language: php
|
||||||
|
parameters: < ProjectEuler\008\input
|
||||||
solve.rb:
|
solve.rb:
|
||||||
desc: Expects the haystack as stdin with optional newlines
|
desc: Expects the haystack as stdin with optional newlines
|
||||||
language: ruby
|
language: ruby
|
||||||
|
parameters: < ProjectEuler\008\input
|
@ -16,5 +16,5 @@ solutions:
|
|||||||
desc: Basic solution
|
desc: Basic solution
|
||||||
language: ruby
|
language: ruby
|
||||||
solve.c:
|
solve.c:
|
||||||
desc: ANSI C solution compiled with gcc-4.3.4
|
desc: C solution compiled with gcc-4.3.4 (Support for long long needed)
|
||||||
language: c
|
language: c
|
@ -13,6 +13,8 @@ solutions:
|
|||||||
solve.php:
|
solve.php:
|
||||||
desc: Expects the matrix as stdin
|
desc: Expects the matrix as stdin
|
||||||
language: php
|
language: php
|
||||||
|
parameters: < ProjectEuler\011\input
|
||||||
solve.rb:
|
solve.rb:
|
||||||
desc: Expects the matrix as stdin
|
desc: Expects the matrix as stdin
|
||||||
language: ruby
|
language: ruby
|
||||||
|
parameters: < ProjectEuler\011\input
|
@ -12,6 +12,8 @@ solutions:
|
|||||||
solve.php:
|
solve.php:
|
||||||
desc: Expects input on STDIN
|
desc: Expects input on STDIN
|
||||||
language: php
|
language: php
|
||||||
|
parameters: < ProjectEuler\013\input
|
||||||
solve.rb:
|
solve.rb:
|
||||||
desc: Expects input on STDIN
|
desc: Expects input on STDIN
|
||||||
language: ruby
|
language: ruby
|
||||||
|
parameters: < ProjectEuler\013\input
|
||||||
|
@ -18,6 +18,8 @@ solutions:
|
|||||||
solve.php:
|
solve.php:
|
||||||
desc: Basic solution
|
desc: Basic solution
|
||||||
language: php
|
language: php
|
||||||
|
parameters: < ProjectEuler\018\input
|
||||||
solve.rb:
|
solve.rb:
|
||||||
desc: Basic solution
|
desc: Basic solution
|
||||||
language: ruby
|
language: ruby
|
||||||
|
parameters: < ProjectEuler\018\input
|
@ -11,4 +11,5 @@ solution: Bruteforce
|
|||||||
solutions:
|
solutions:
|
||||||
solve.php:
|
solve.php:
|
||||||
desc: Expects data on STDIN
|
desc: Expects data on STDIN
|
||||||
language: php
|
language: php
|
||||||
|
parameters: < ProjectEuler\022\input
|
Reference in New Issue
Block a user