Skip to content

Instantly share code, notes, and snippets.

@coderaven
Last active December 15, 2015 13:39
Show Gist options
  • Save coderaven/5268829 to your computer and use it in GitHub Desktop.
Save coderaven/5268829 to your computer and use it in GitHub Desktop.
Project Euler Problem 42 Solution
require 'open-uri'
(o = "\n") && ( puts "There are a total of %s " % (open('http://projecteuler.net/project/words.txt', 'r'){ |f| IO.readlines(f).to_s.gsub(/\"|\\|\[|\]/,"").split(",").inject(0){|t,s| (z =( Math.sqrt(8 * (c = s.split(//).inject(0){|n,l| n+(l.ord-64)}) +1)-1)/2) % 1==0 ? (t+1 if ((o = o + "#{t+1}.#{s} (#{c},#{z.to_i})\n") || true) ) : t}}.to_s + "triangle words:" + o) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment