Skip to content

Commit

Permalink
Problem 24 (Level 1!!!)
Browse files Browse the repository at this point in the history
  • Loading branch information
zamith committed Jul 25, 2011
1 parent fd5102e commit 89d25ea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion 21-30/023.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
end
end

# Our filter is ready (with all abundant numbers set to 1), just sum them all!
# Our filter is ready (with all the numbers that are sums of abundant numbers set to 1),
# just sum them all!
sum_abundants=0
(1..n).each do |pos|
sum_abundants+=pos if abundant_nums_filter[pos] == 1
Expand Down
32 changes: 32 additions & 0 deletions 21-30/024.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env ruby -w

require_relative '../Utils/MathUtils'
include MathUtils

# Based on the course notes of the University of Exeter's Computational Physics class (PHY3134)

values=[0,1,2,3,4,5,6,7,8,9]
$result=[]


def permute(values,start,n)
if start == n-1
$result << values.join
else
(start...n).each do |pos|
tmp = values[pos]

values[pos] = values[start]
values[start] = tmp

permute(values,start+1,n)

values[start] = values[pos]
values[pos] = tmp
end
end
end

permute(values,0,values.size)
# Because the array starts at 0
$result.sort[999999]

0 comments on commit 89d25ea

Please sign in to comment.