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 'erb'
|
||||
|
||||
require 'open3'
|
||||
cli = { 'php' => 'php', 'ruby' => 'ruby', 'javascript'=>'node', 'js'=>'node', 'c' => 'tcc -run'}
|
||||
problem = YAML::load_file(ARGV[0] + "/desc.yml")
|
||||
output = ERB.new(IO.read('template.rt'))
|
||||
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')
|
||||
require 'terminal-table'
|
||||
@ -30,4 +45,4 @@ if(ARGV[1] == 'table')
|
||||
end
|
||||
table = Terminal::Table.new(:headings => ['Code','Title','Solved'],:rows => rows)
|
||||
puts table
|
||||
end
|
||||
end
|
||||
|
@ -21,3 +21,6 @@ solutions:
|
||||
solve.js:
|
||||
desc: NodeJS solution
|
||||
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
|
||||
solve.js:
|
||||
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];
|
||||
if(fib[2] % 2 == 0)
|
||||
sum += fib[2];
|
||||
fib[0] = fib[1];
|
||||
fib[0] = fib[1];
|
||||
fib[1] = fib[2];
|
||||
}
|
||||
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;
|
||||
(100..1000).each do |num1|
|
||||
(100..1000).each do |num2|
|
||||
sum = num1 * num2
|
||||
if( sum > max and sum.to_s.reverse == sum.to_s)
|
||||
max = sum
|
||||
i = 0
|
||||
while (true)
|
||||
i = i + 20
|
||||
div = 19
|
||||
|
||||
while((i % div) == 0)
|
||||
div = div - 1
|
||||
if(div == 0) then
|
||||
puts i
|
||||
exit
|
||||
end
|
||||
end
|
||||
end
|
||||
print max
|
||||
end
|
@ -19,6 +19,6 @@ solutions:
|
||||
solve.rb:
|
||||
desc: Basic Ruby solution
|
||||
language: ruby
|
||||
solve.rb:
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
@ -11,6 +11,8 @@ solutions:
|
||||
solve.php:
|
||||
desc: Expects the haystack as stdin with optional newlines
|
||||
language: php
|
||||
parameters: < ProjectEuler\008\input
|
||||
solve.rb:
|
||||
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
|
||||
language: ruby
|
||||
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
|
@ -13,6 +13,8 @@ solutions:
|
||||
solve.php:
|
||||
desc: Expects the matrix as stdin
|
||||
language: php
|
||||
parameters: < ProjectEuler\011\input
|
||||
solve.rb:
|
||||
desc: Expects the matrix as stdin
|
||||
language: ruby
|
||||
language: ruby
|
||||
parameters: < ProjectEuler\011\input
|
@ -12,6 +12,8 @@ solutions:
|
||||
solve.php:
|
||||
desc: Expects input on STDIN
|
||||
language: php
|
||||
parameters: < ProjectEuler\013\input
|
||||
solve.rb:
|
||||
desc: Expects input on STDIN
|
||||
language: ruby
|
||||
parameters: < ProjectEuler\013\input
|
||||
|
@ -18,6 +18,8 @@ solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
parameters: < ProjectEuler\018\input
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
||||
parameters: < ProjectEuler\018\input
|
@ -11,4 +11,5 @@ solution: Bruteforce
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Expects data on STDIN
|
||||
language: php
|
||||
language: php
|
||||
parameters: < ProjectEuler\022\input
|
Reference in New Issue
Block a user