Wrote a quick ruby script that someone might find useful. It will recursively find and list readonly files from a passed in directory. There's also a an array of file extensions you can exclude.
Nothing Fancy:
require 'find'
# update to exclude by file extension
exclude_extensions = ['.jpg','.txt','.png','.gif','.git']
if(ARGV[0] == nil) then
puts "Please pass in a directory."
exit
end
puts "Searching for NON read only files"
puts "Excluding: " + exclude_extensions.join("\s")
writable = []
Find.find(ARGV[0]) do |path|
if File.file?(path) and File.writable?(path) then
if exclude_extensions.include?(File.extname(path))
writable.push path
end
end
end
if writable.size then
puts "Writable Files:"
puts "\t" + writable.join("\n\t")
else
puts "No writable files."
end
Tags: ruby
I've been playing a bit with Silverlight this weekend, and I made a little app based on little game called Flood-It! Unfortunately, at the time I started I couldn't remember the name of the app, so it's a bit of an interpretation...
Anyhow, the goal of the game is to 'flood' the screen with all one color. It's a bit difficult to explain, so just click around a bit and it will start making sense.
So far I've really liked working in Silverlight, it's very similar to Flex except that C# blows ActionScript out of the water. I've got a few more little projects I'd like to try before I give my final verdict, so don't touch that dial!
Tags: c#, game programming, silverlight
I spent some time playing around with a way to reduce calculations by constructing something akin to a sieve, (2^16 is the same as 4^8 and 16^4), but it turns out that the brute force solutions runs in under a second on my machine so it seemed silly to spend any more time with it.
Ruby even minds the big numbers for me, so the solution is quite trivial:
How many distinct terms are in the sequence generated by a^(b) for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?
MIN, MAX = 2,100
values = []
(MIN..MAX).each do |base|
(MIN..MAX).each do |power|
values << base**power
end
end
puts values.uniq.length
Tags: project euler, ruby
I've taken ill for the last two days, so I've been working on a couple Project Euler problems in between trips to the bathroom.
Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n = 0.
Since you start with n = 0, you know that b always has to be prime in order to satisfy n = 0.
Next, if b must be prime, and all primes greater than 2 are odd, and we don't care about expressions resulting in less than 3 consecutive primes (example expression has 40), then we know that all values of a must be odd in order to satisfy n = 1!
I also suspect that for the number of consecutive primes we need to 'win', that we only need to look at negative values of a, but I'm having a heck of a time trying to prove it.
require 'prime_generator'
# pre-calculate primes
MAX = 1_000
primer = Prime_Generator.new MAX
primes = primer.stack
product = 0
highest = 0
# a must be odd
(0..MAX).each do |i|
next if i & 1 == 0
# b must be prime
primes.each do |b|
# a can be positive or negative
[i,-i].each do |a|
n = 0
while n += 1 do
break unless primer.is_prime?(n ** 2 + a * n + b)
end
if highest < n
highest = n
product = a * b
end
end
end
end
puts product
And here's the prime generator I'm using:
class Prime_Generator
attr_reader :stack
def initialize max = 3
@stack = [1,2,3]
fill_to max
end
def fill_to max
n = 1
while true do
n += 4
return @stack if n > max
@stack << n if is_prime? n
n += 2
return @stack if n > max
@stack << n if is_prime? n
end
end
def is_prime? n
return false if n <= 0
max = Math.sqrt(n).floor
fill_to(max + 1) if max > @stack.last
@stack.each do |i|
next if i == 1
return true if i > max
return false if n % i == 0
end
true
end
end
You can find more Project Euler solutions here: https://svn2.assembla.com/svn/joe-zack-personal/projects/euler/ruby/
Tags: project euler, ruby
After spending a few dozen hours playing The War of the Roosevelts, I realized that there was a wee bit of room for improvement.
Now, there's like cards and stuff.
Enjoy.
Here's the source, but I still won't waste my time looking up the svn link.
Tags: flex, game programming