- 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
Casio calculator:
"Number of lockers"?->A Int √A->Dim List 1 For 1->B To √A B^2->List 1[B] Next List 1
Admin
Sweet...it would be cool if you would categorize the previous two entries so they show up in the category list
Admin
Admin
A locker will remain open at the end if it's been touched an odd number of times. Each locker will be touched once for each of its integral factors, including 1 and itself.
For a given number n, any integral factor f (1 < f < n), there will be a complementary factor f' (1 < f < n). Collected together, the only way these factors will number evenly will be if f=f' and n=f^2.
Therefore, the resulting opened lockers will be squares of the numbers from 1..sqrt(n).
Admin
A more compact Funge solution (created using BeQunge). BeQunge seems to differ from the Funge-98 spec in terms of the directions produced by the 'w' instruction, so results may be incorrect with different interpreters.
Anyway, here's the code:
Admin
Function in Turbo Pascal
Admin
Follow-up question: which lockers are toggled the LEAST?
Admin
since the call was for a function definition and the array is an acceptable return value, this can be golfed further to:
sub l{map{$*$}1..sqrt pop}
which has a golf count of 29 -- not counting the perl invocation or:
perl -e 'sub l{map{$*$}1..sqrt pop}'
38 with the perl invocation but without an invocation of the function.
Admin
Admin
In R:
Admin
Are you sure that ++c*c works as expected in java? It would not work in c or c++.
Admin
LabVIEW:
[image]Note: LabVIEW sucks
Admin
List<int> getOpenLockers(int NumLockers) { List<int> OpenLockers = new List<int>(); int inc = 0; for (int i = 0; i + inc + 1 <= NumLockers; i++) { OpenLockers.Add(i + inc + 1); i += inc; inc += 2; } return OpenLockers; }
Admin
I don't believe that a bunch of football players could correctly determine what they had to do.
Admin
Seems fairly simple. The state of each locker is just a property of the number of prime factors it has.
For example, 6 has prime factors of 1, 2 and 3. That's 3 prime factors. The 6th locker will be toggled 3 times and end up open.
Odd # of factors = open Even = closed.
I find it hard to believe a bunch of nerds couldn't figure this out.
Admin
Locker #1 only gets toggled once. Though I vote for the lockers in the next hall over. They don't get toggled at all during this experiment.
Admin
Actually scratch that, I meant factors not prime factors
Admin
Very simple. The lockers that stay open are the ones whose #'s are perfect squares. 1,4,9,16,.....
Admin
As it has been pointed out, the lockers that stay open are lockers that have an odd number of divisors. If you only know the number of the locker, you can somewhat brute force it by simply figuring out how many divisors it has.
Java code. I don't consider this "brute force" because it doesn't go thru each locker and toggle it several times. Although there are better ways to do this.
Admin
Perl golf... here's 27 chars :)
sub f{map$_**2,1..sqrt pop}
Admin
The obligatory BrainFuck:
++++++++++[>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<[->+>+>+<<<]>>>[-<<<+>>>]<<[>[>+<-]<<[->>+>>+<<<<]>>>>[-<<<<+>>>>]<<<-]>>[->+>+<<]>>[-<<+>>]<[>++++++++++[->>+>+<<<]<[>>>[-<<<-[>]>>>>[<[>]>[---------->>]<++++++[-<++++++++>]<<[<->[->-<]]>->>>[>]+[<]<<[->>>[>]<+[<]<<]<>>]<<]<+>>[->+<<+>]>[-<+>]<<<<<]>>[-<<+>>]<<]>[-]>>>>>>[>]<[.[-]<]<<<<<<<>[-]>[-]+++ +[<+++ +++ +++ ++>-]<.>+ +++[<--->-]<.<<<<-]
Output: 100, 81, 64, 49, 36, 25, 16, 9, 4, 1,
Admin
Brute force Delphi:
Admin
Anguriel: Locker #1 only gets toggled once... Brad: Primes. Twice each.
Correct so far. What about three times? Four?
Admin
Everybody failed this test. Have you read the problem?
It doesn't say "after performing toggles for i=1..n on n lockers", it doesn't even say "after toggling every mth locker for m=1..n". It says "after toggling n lockers" where one toggling is defined as "changing the state of one door". The sample solutions for n=1 and n=4 are also wrong. It should be: f(1)={1} and f(4)={1;2;3;4}. So TDWTF failed its own test. The solution "square numbers" is as trivial as it is wrong, because that's only the solution for the simplest case, where the factors go from 1 to the number of lockers.And your form is broken, it doesn't submit.
Admin
Admin
And it isn't even correct. Here's a better one, which doesn't generate any warnings and produces a list of the most toggled lockers:
Admin
Admin
Admin
Here's my solution, without looking at comments.
and Results
Admin
Umm... wasn't that the scenario given?
doublechecks
Why yes... yes it was. What problem were you thinking of?Admin
PS
for (int i=1; ii < 100; ++i) cout << ii;
is more computationally efficient than using sqrt - a single multiply is much cheaper than a sqrt.
that's why many games use radius bounding spheres and use distance squared instead of distance - skip the unneeded and expensive sqrt
Admin
I think the solution is knowing the problem beforehand (which seems doable given the circumstances) and a) look up the solution and get some acting exercise to make solving it look believable, make a few mistakes at first and b) do something funny with the lockers and / or the corridor.
Admin
In Befunge98:
Admin
Simple python solution with list comprehensions...
Admin
In line with
...and... I would guess, several doors hanging by one hinge, at least a couple lying on the floor; papers, books, gym clothes and assorted high-school-type crap scattered willy-nilly; perhaps a jock or two moaning in pain after slipping on said crap.Oh, wait... these lockers are unused. Forgot. Okay, switch halls, everybody.
Admin
javascript:getPaula() (copy+paste in same window)... nuff said... for now.
Admin
Admin
If the same hallway and rules were used for every "locker challenge" in the story, the best solution would have been to just remember the results from the last time. For bonus points, prank the teacher by putting stickers on the inside of the appropriate lockers saying This locker will be open.
(Captcha = paratus, latin for "ready". Hmm...)
Admin
Admin
perl -e "while($**2<$ARGV[0]){$++};print" 100
Admin
I thought that was the whole point!
Admin
Didn't notice the bonus points bit. Here's a Ruby implementation that sorts the lockers by the number of times they were toggled as well. (very inefficient divisor counter, but the efficient one is another dozen lines of code ;) )
Admin
I was pretty proud of myself with this one, until I realized all the numbers were perfect squares. Anyway, my function returns a list with the open open lockers = True and the rest = False.
Admin
ahh, my daily wtf: untested and excessively complicated
Admin
Both are called as "getOpenLockers(100);"
function getOpenLockers(n) { var x = 1; var i = 1; var result = '';
}
or
function getOpenLockers(n, x, i) { if (!x) i = (x = 1) + 2; return (x > n) ? '' : ((x > 1) ? ', ' : '') + x + getOpenLockers(n, x + i, i + 2); }
Admin
I know it is not high programming:
put this in Excel to cell B1, and copy it to a 100x100 area :) =IF(MOD(ROW(),COLUMN()-1)=0, IF(A1=0,1,0),A1)
Column CW is the solution itself
Admin
Admin
(I haven't read the comments yet).
The solution is found by determining the number of factors. 1 has a single factor (1) and remains open. 2 has two factors (1,2) and is opened then closed. 3 has two factors (1,3) and is opened then closed. 4 has three factors (1,2,4) and is opened, closed, and reopened.
Each locker that is left open has an odd number of factors. Factors come in pairs matched from outside in. For example 8 (1,2,4,8) has two pairs of factors: 18 and 24. Odd numbers of factors also come in pairs matched from outside in, but the innermost number is used twice. For example 4 (1,2,4) has two pairs of factors: 14 and 22. The odd number of factors are only found in numbers that are squares of one of the factors.
The easiest way to calculate the open lockers is to find the square numbers.
Answer in C#
CAPTCHA: damnum
Admin
Edit: Utter fail on the five toggles. Fixed in posting below.
Admin