From e99ce2c5324fc1b2c6dde6723f92d4f5a1cf143b Mon Sep 17 00:00:00 2001 From: FuryFire Date: Thu, 15 Mar 2012 13:12:02 +0100 Subject: [PATCH] Added first version of helper tool --- CT.rb | 32 ++++++++++++++++++++++++++++++++ Generic/FIZZBUZZ/desc.yml | 9 +++------ Generic/desc.yml | 4 ++++ ProjectEuler/022/desc.yml | 1 - ProjectEuler/023/desc.yml | 2 -- ProjectEuler/024/desc.yml | 11 +++++++++++ ProjectEuler/024/solve.php | 25 +++++++++++++++++++++++++ ProjectEuler/desc.yml | 4 +--- ct.bat | 1 + template.rt | 15 +++++++++++++++ 10 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 CT.rb create mode 100644 Generic/desc.yml create mode 100644 ProjectEuler/024/desc.yml create mode 100644 ProjectEuler/024/solve.php create mode 100644 ct.bat create mode 100644 template.rt diff --git a/CT.rb b/CT.rb new file mode 100644 index 0000000..0b9944d --- /dev/null +++ b/CT.rb @@ -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 \ No newline at end of file diff --git a/Generic/FIZZBUZZ/desc.yml b/Generic/FIZZBUZZ/desc.yml index bd979c1..45b3ec1 100644 --- a/Generic/FIZZBUZZ/desc.yml +++ b/Generic/FIZZBUZZ/desc.yml @@ -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 \ No newline at end of file diff --git a/Generic/desc.yml b/Generic/desc.yml new file mode 100644 index 0000000..61df3e6 --- /dev/null +++ b/Generic/desc.yml @@ -0,0 +1,4 @@ +title: Generic +url: http://google.com + +desc: Various problems that doesn't fit any catagory diff --git a/ProjectEuler/022/desc.yml b/ProjectEuler/022/desc.yml index bdf56f0..670cce6 100644 --- a/ProjectEuler/022/desc.yml +++ b/ProjectEuler/022/desc.yml @@ -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: diff --git a/ProjectEuler/023/desc.yml b/ProjectEuler/023/desc.yml index 4dfc911..b16fd8d 100644 --- a/ProjectEuler/023/desc.yml +++ b/ProjectEuler/023/desc.yml @@ -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 diff --git a/ProjectEuler/024/desc.yml b/ProjectEuler/024/desc.yml new file mode 100644 index 0000000..1205c24 --- /dev/null +++ b/ProjectEuler/024/desc.yml @@ -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: \ No newline at end of file diff --git a/ProjectEuler/024/solve.php b/ProjectEuler/024/solve.php new file mode 100644 index 0000000..848a63d --- /dev/null +++ b/ProjectEuler/024/solve.php @@ -0,0 +1,25 @@ + +<%= 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 %> \ No newline at end of file