Brute Force Ruby II

Talking about “More is Less”, my dear friend and collegue Tobias Fors managed to distill the code a bit:

for k in 1...100000
  t = (k * k).to_s
  if t.length == 10 and t.split(//).sort.join == "0123456789"
    print k, " * ", k, " = ", t, "n"
  end
end

Brute Force Ruby I

Is there a number (k) that multiplied by itself yields a result (t) that contains all the digits 0-9 and nothing else? 

def contains0to9(tarr)
  tarr.index("0") and tarr.index("1") and tarr.index("2") and tarr.index("3") and tarr.index("4") and tarr.index("5") and tarr.index("5") and tarr.index("6") and tarr.index("7") and tarr.index("8") and tarr.index("9")                 
end

for k in 1...100000
  t = k * k
  tarr = t.to_s.split("")
  if tarr.length == 10 and contains0to9(tarr)
    print k, " * ", k, " = ", tarr, "n"
  end
end

Zug Zug

I’ve had shell access on textdrive.com for almost a week now. Long-time-no-see-unix-commands slowly find their way back to the more conscious part of my brain. I’ve been here before, in Unixland, although my memories have faded. Let’s see… ls -u, alrighty! tar xvf wordpress.tar.gz… Ta da! I’ve finally earned my beard – I R admin!