 Feature Articles
 CodeSOD
 Error'd
 Forums

Other Articles
 Random Article
 Other Series
 Alex's Soapbox
 Announcements
 Best ofâ€¦
 Best of Email
 Best of the Sidebar
 Bring Your Own Code
 Coded Smorgasbord
 Mandatory Fun Day
 Off Topic
 Representative Line
 News Roundup
 Editor's Soapbox
 Software on the Rocks
 Souvenir Potpourri
 Sponsor Post
 Tales from the Interview
 The Daily WTF: Live
 Virtudyne
Admin
Programming Praxis has officially gotten its own category. Next up: perhaps adding a field for the programming language, so we can build an index.
As for last week's, there were some great solutions... some of the more interesting ones involved XSLT, ZX Spectrum BASIC version, Piet, and as a Minsky machine.
Admin
public static void main(String[] args) { int num = 100; int i=1; int k=1; while(k<num){ k=i*i; i++; System.out.println(k); }
Admin
#!perl
sub lockers { return map $_**2, 1..sqrt shift }
Admin
i don't have a method of solving this problem, but i can clearly see the pattern when it's done  closed lockers in runs of 2,4,6,8,10,12,14,16,18 with a single open locker between them
how delightful!
Admin
Umm squares of 1 to 10?
Captcha "eros" .....I love you too!
Admin
Or to put it more simply The open lockers are i^2 where i runs from 110.
Admin
The open lockers are perfect squares.
The reasoning is simple: nonperfect squares have an even number of factors. The jocks toggle a number for every factor it has. Therefore every door should be toggled an even number of times and should therefore end closed (the starting state).
However, perfect squares have an odd number of unique factors, because one of the factors is repeated. Because of this, perfect squares are toggled for their square root which has no pair to reverse the toggle, so the door ends up open (the opposite state it started in).
Make sense?
Admin
Paste this formula in Excel and use copydown
=ROW(A1)^2
Admin
Somehow I think that makes it less fun.
Admin
vbs file, work in nearly any windows
a = inputbox("locker?")
for i = 1 to a l = l+1 b = b & i & " " i = i + (2*l) next
msgbox b
Admin
Admin
Haskell:
Admin
Looks like the mosttoggled locker is the 96th one, with 12 toggles.
Admin
DOS, because I'm too lazy to SSH into my linux machine:
Admin
for me, I saw the pattern +3, +5 , +7, +9, +11, +13, +15, +17 and +19
not i^2
Admin
I also noticed this pattern and it is trivial to code:
From the explanation about the squares, we can deduce why this works:
(n+1)^2 = n^2 + 2n + 1
Admin
The header of the article shows up as white on white in chrome, maybe this category hasn't had a header color assigned to it yet?
Admin
Not exactly awesome:
Admin
So... Not having fun in your job as a programmer ?
Admin
Thanks for pointing out the rythm!
Classic ASP:
Admin
Admin
Thinking just shortly (12 min) about it, I'd say that exactly the square numbers stay open.
Admin
input: totalLockerNum
max = floor(sqrt(totalLockerNum))
for i=1; i<=max; i++ { result = i**2; add result to array } return array
Admin
Yes, that would be the pattern for perfect squares.
Admin
.NET Solution:
Admin
i just watched the example and i feel like a jock
stupid nerds with their fancy "square" numbers, nobody needs em!
Admin
How sad :(
Admin
what with the brilliant paula being brillant?
Admin
Answer:
perfect squares.
using formulae:
Brute force:
Solved this ages ago for rosetta code: (http://rosettacode.org/wiki/100_doors#Common_Lisp)
Admin
Python:
Admin
Using this excuse to practice some Groovy:
public List getLockers(int numLockers) { (1..numLockers).collect{ it*it } }
Any groovy programmers that want to show me better ways to do this, please point them out. :D
Admin
Pretty simple :) after you watch the simulation... getOpenLockers(n){open = 1;count = 3; while(open<=n) { print open; open += count;count += 2;} } I'll leave the mathematical solution for somebody else.
Admin
Yup, only one small change....
Admin
I AM NOT A GROOVY PROGRAMMER.
It looks like it will return the squares from 1 to numLockers**2, which might not be what you want.
Admin
I don't see where it says n should be less than 100.
Admin
And the limit of 100 is irrelevant. That just gives us the maximum perfect square we care about.
Admin
Admin
Addendum (20090805 10:12): Addendum: never mind. I guess I'm just not thinking straight about this.
Admin
The locker toggled the most is the locker whose prime factors can create the greatest number of combinations. (locker ... combinations ... get it?).
At first, I think 64 might be a good choice, but (2,2,2,2,2,2) creates only 6 combinations. If I replace a 2 with a 3, I describe locker 96, and I can now create 11 combinations. Applying my knowledge of cribbage, I see that I can replace three 2s with two 3s to describe locker 72 (2,2,2,3,3), which also creates 11 combinations.
Admin
Wrote this quick in C#
Admin
I would bet that Mr. Zargas was the coach of the football team. This challenge is EXTREMELY biased towards the jocks. I respectfully submit that in order to figure out the function, you HAVE to iterate (brute force) at SOME point in time.
SHENANIGANS!
Admin
25 can be divided by 1, 5 and 25. That's 3 factors > odd.
Admin
And a slightly smaller version in JS
BTW, I'm getting an awful lot of errors when posting lately...
Admin
Admin
Re: "96 has the most"...
Other numbers not above 100 with 12 distinct factors:
60: 1 2 3 4 5 6 10 12 15 20 30 60 72: 1 2 3 4 6 8 9 12 18 24 36 72 84: 1 2 3 4 6 7 12 14 21 28 42 84
Admin
simply  squares of prime numbers (or perfect squares)
I'm amazed with amount of i^2 solutions. Think a bit longer before posting.