Added first version of helper tool

This commit is contained in:
FuryFire 2012-03-15 13:12:02 +01:00
parent 823b0a332a
commit e99ce2c532
10 changed files with 92 additions and 12 deletions

32
CT.rb Normal file

@ -0,0 +1,32 @@
require "yaml"
require 'erb'
problem = YAML::load_file(ARGV[0] + "/desc.yml")
output = ERB.new(IO.read('template.rt'))
puts output.result()
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|
row = [e['code'],e['title'],e['solved']]
rows << row
end
table = Terminal::Table.new(:headings => ['Code','Title','Solved'],:rows => rows)
puts table
end

@ -1,20 +1,17 @@
title: FizzBuzz
url: http://projecteuler.net/problem=1
desc: |
The classical coding challenge. Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
desc: The classical coding challenge. Write a program that prints the numbers from 1 to 100. But for multiples of three print Fizz instead of the number and for the multiples of five print Buzz. For numbers which are multiples of both three and five print FizzBuzz.
solution: |
See the code...
solution: See the code...
solutions:
solve.php:
desc: Basic solution
usage:
language: php
solve.rb:
desc: Basic solution in Ruby
language: ruby
solve.c:
desc: ANSI C solution (Tested with TCC)
language: c
language: c

4
Generic/desc.yml Normal file

@ -0,0 +1,4 @@
title: Generic
url: http://google.com
desc: Various problems that doesn't fit any catagory

@ -6,7 +6,6 @@ desc: |
For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 53 = 49714.
What is the total of all the name scores in the file?
(See file input)
|
solution: Bruteforce
solutions:

@ -6,8 +6,6 @@ desc: |
A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.
As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.
Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.
|
todo: Improve algorithm
solution: From we http://mathworld.wolfram.com/AbundantNumber.html we cheat and limit our search to 20161

11
ProjectEuler/024/desc.yml Normal file

@ -0,0 +1,11 @@
title: What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
url: http://projecteuler.net/problem=24
desc: |
A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:
012 021 102 120 201 210
What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
todo: Improve algorithm -
solution: Bruteforce
solutions:

@ -0,0 +1,25 @@
<?php
function fac($number) {
if($number == 1)
return 1;
return $number * fac($number-1);
}
$result = array(0,0,0,0,0,0,0,0,0,0);
$endsteps = 1000000;
$cstep = 0;
$cdigit = 9;
while($cdigit != 0) {
do{
$result[9-$cdigit]++;
$cstep += fac($cdigit);
} while ($cstep < $endsteps) ;
echo "Done with $cdigit - steps:$cstep\n";
$cdigit--;
}
echo "DONE!";
print_r($result);
echo " - ".$cstep ."\n";
echo "Result: 2783915460";

@ -1,6 +1,4 @@
title: ProjectEuler.net
url: http://projecteuler.net/
desc: |
Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.
desc: Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.

1
ct.bat Normal file

@ -0,0 +1 @@
ruby CT.rb %1 %2

15
template.rt Normal file

@ -0,0 +1,15 @@
<%= problem['title'] %>
<%= problem['url'] %>
Desc:
<%= problem['desc'] %>
<% if( problem['solution'] and problem['solutions'] ) %>
Solution:
<%= problem['solution'] %>
<% problem['solutions'].each do |sol| %>
<%= sol[0] %>
<%= sol[1]['desc'] %>
<%= sol[1]['language'] %>
<% end %>
<% end %>