43
4
As programmers, we all know the saying: "You can have it fast and good, but it won't be cheap, you can have it cheap and good, but it won't be fast, or you can have it fast and cheap, but it won't be good."
For this challenge, you are implementing an imaginary configuration tool for your custom programming services. You should render a set of three check boxes, with a heading of "SELECT ANY TWO":
SELECT ANY TWO
☐ FAST
☐ CHEAP
☐ GOOD
Once two items have been selected, the third item must be disabled. Upon deselecting one of the two selected items, all options must again be enabled. Put another way, if zero or one items are selected, all are still enabled, but if two items are selected, the third must be disabled.
No special controls allowed. The check boxes should be the standard check box in your language of choice. For example, don't use a "CheckBoxList" control, if your language has one. I'm imagining most entries will be HTML/jQuery, but that is not a rule. This is code golf, looking for the shortest entry.
WINNERS SO FAR
I'll break it down into categories. There are some clear winners:
jQuery: nderscore, Mr. Tenacity Under 100b when you exclude text "resources". Honorable mention should also go to Matt for introducing the jQuery concepts that many took inspiration from.
Dyalog APL: marinus, a.k.a. Mr. Unicode How do you type all those things? I can see why you would want to write short programs.
PHP: SuperScript I believe this is the shortest entry that actually disables rather than deselecting the third option, following the strictest interpretation of the rules.
Can I just make it so that only two can be selected at a time? So that selecting the third de-selects one of the other ones? Or perhaps add an accept button that gets greyed out if 3 options are selected? – Justin – 2014-05-08T03:30:45.920
7@Quincunx - Since there is no heuristic (outside of mind-reading) that could decide which one to deselect, this would confuse the user... so I'll have to say no, because we don't want the first impression of our custom software services to be a bad one. ;) – Bruce Pierson – 2014-05-08T03:53:49.763
This question interested me in Python 3's tkinter, so I am trying to learn that now. IMO, the best way to learn GUI is by trial and error. I tried this: http://ideone.com/YHLZIQ . Result: rapid opening of new GUIs. I had to open task manager to close them. :-). Image (the number soon climbed to 340: http://i.stack.imgur.com/c9wQi.png)
– Justin – 2014-05-08T05:29:48.180The bonus contest should be another question as there is no objective primary winning criterion or any description of the "bonus". It said that code should be "...elegant and flexible..." and "...concise and clear..." which is against [tag:code-golf]. VTC as unclear what you are asking. Please don't radically change questions long after they are asked. – user80551 – 2014-05-08T17:38:02.837
Fair enough, removed. – Bruce Pierson – 2014-05-08T17:42:03.603
1@BrucePierson Actually, there is. We could deselect the oldest selected checkbox. However, the code for that would be much more than the code you require. – Justin – 2014-05-08T20:15:05.947
@Quincunx Well, no question that your suggestion fits the precise definition of "heuristic" - certain parts of the definition, anyway. :) – Bruce Pierson – 2014-05-08T20:40:37.857
Is it permitted to prevent the user from checking the 3rd checkbox instead of actually disabling it? – nderscore – 2014-05-08T23:20:54.087
@nderscore yes.
– Justin – 2014-05-09T01:09:17.657What do you mean by "Don't use a check box list"? If you applied this too strictly, one wouldn't even be allowed to use jQuery. – Bergi – 2014-05-09T13:50:12.937
"Do not use these controls for SQLite." – Michael – 2014-05-09T15:43:05.813
I've been having a discussion on meta, are the requirements for this challenge to write a function or a fully functional program? http://meta.codegolf.stackexchange.com/q/1550
– iamkrillin – 2014-05-10T13:25:32.903@iamkrillin I think all the entries so far are executable in their context. Obviously a framework of some kind is usually present (browser, Qt, etc.). But it must display the page/form and allow interaction. – Bruce Pierson – 2014-05-10T16:22:22.633
If something is good and cheap, it won't be fast. Therefore it won't be cheap either. – bjb568 – 2014-05-11T20:52:10.627
<anal>"Pick two" sounds much better than "Select any two" – o0'. – 2014-05-12T11:00:36.287
Would we be allowed to simply have
SELECT ANY TWO
be the title of the window, rather than a label inside? – Justin – 2014-11-03T08:18:04.263