11 ms·
Return True to Win
- lalala1995 10y agoPlease more levels
- idbehold 10y agoYou've already finished wat, undef, random3, and random4?
- fennecfoxen 10y ago> wat, undef Oh, undef is as easy as knowing HTML trivia. Getting a falsey value to return an arbitrary string when invoked as a function is at least a little harder... > random3 ... is almost as easy as random1 > random4 is exactly as impossible as it looks
- dou4cc 10y agoThe game shows us how ugly JS is.
- tomelders 10y agoSwift. The Javascript of tomorrow, today!
- k_bx 10y agoPureScript. The Swift of today. Yesterday, today and tomorrow!
- tomelders 10y agoBut it compiles to ES5. At this rate, we'll be deploying ES5 for the rest of human history while we all pretend we're writing ES451. And it's whitespace significant, which is something only maniacs like in a programming language. I'm half joking, don't get too offended... But whitespace significance is madness.
- posterboy 10y agoIndeed, I refuse to believe there should be a solution to the 'reflexive' task.
- teraflop 10y agoThat one isn't specific to Javascript, though. If you can find a mainstream language that doesn't have any values that aren't equal to themselves, I'll give you a cookie. (Going from memory of the last time I tried this challenge, since I can't get it to load at the moment.)
- posterboy 10y agoThe important property of evaluation is determinism defined by the equality of the output. Classically, id(x) != id(x) is logically inconsistent. Boolean Logic and natural languages are pretty mainstream in my opinion. Do you mean programming languages? If IEEE whatsthenumber is implemented in the FPUs to provide fcmp (Floating-point Compare Instruction), the languages don't have much of a choice. When there are different types of equality, ie. compare instructions, you have no equality. That's maybe a bit binary. I'm sorry, I thought this was Computer Science.
- Etzos 10y agoYou seem to be splitting hairs and I'm not entirely sure why. Following the flow of conversation it should be pretty easy to infer the parent was referring to programming languages. Originally you said you don't think there should be a solution to the reflexive problem, and that in reply to a comment mentioning that Javascript was ugly (which is where the context of _programming_ language came from). I, and I believe the parent as well, took that to mean that you consider Javascript ugly because you don't believe it should operate the way it does. However, the point the parent was trying to make is that this is something common to all (programming) languages which follow the IEEE 754 standard and is therefore not some special case which makes Javascript any more ugly than another (programming) language. It may not seem obvious and it may seem logically inconsistent but, like you said, this is computer science and things don't always work exactly the way we think they should. Usually because the obvious logical solution has problems when implemented so we change things around. In this case, NaN != NaN because of some of the limitations at the time IEEE 754 was proposed.
- Zekio 10y agoI quite like this kind of challenge :)
- plank 10y agoTook me a couple of tries... (Spoiler): Anyone anything shorter then 4 characters (two characters)?
- plank 10y agoAh. 2 distinct characters now.
- lma21 10y agoHow did you solve the reflexive? I'm not getting at anything :(
- nxzero 10y agoReminds me of "The Little Lisper" and coding koans; honestly thought it'd be harder to "win" the challenge.
- deleted 10y ago[deleted]
- xyclos 10y agoThis is a nice challenge to start the morning. However, on mobile the input loses focus after each individual character typed which is quite frustrating.
- grabcocque 10y ago'Break JS to win!'
- idbehold 10y agoLet me document all the reasons I dislike the HTML spec: it defines a willful violation of the ECMAScript standard.
- xeniak 10y agoCan you elaborate?
- idbehold 10y agoWell, it's kind of a hint for solving some of the more "that's impossible" problems on here. I don't want to give the whole thing away.
- fennecfoxen 10y agoI'll use a link shortener to prevent spoilers. This link elaborates exactly which rules are abused: https://goo.gl/mu5xtr https://goo.gl/mu5xtr "These requirements are a willful violation of the JavaScript specification current at the time of writing. The JavaScript specification requires that ToBoolean return true for all objects, and does not have provisions for objects acting as if they were undefined for the purposes of certain operators. This violation is motivated by a desire for compatibility..." with old Internet Explorer.
- fauria 10y agoThis table is quite useful to solve some problems: https://dorey.github.io/JavaScript-Equality-Table/ https://dorey.github.io/JavaScript-Equality-Table/
- liquidise 10y ago> Moral of the story: Always use 3 equals unless you have a good reason to use 2. NaN === Nan // => false [] === [] // => false {} === {} // => false [1] === [1] // => false [0] === [0] // => false I guess i never see the gains in the triple vs double equal sign wars.
- idbehold 10y agoDo any of those return true if you use double equals? The distinction only really comes up when you have to different types on either side and then It will coerce one of the types to match the other.
- TAForObvReasons 10y agoThat is correct. The canonical example is string-numeric coercion: "0" == 0 && "0" !== 0
- TAForObvReasons 10y agoNone of those are true when using `==` either. The NaN example comes directly from IEEE754 The others are based on the fact that the two sides are not referring to the same object. C "equivalents" of your examples: int x[0], y[0]; x == y; // false typedef struct {} empty_t; empty_t *x, *y; x == y; // false int x[] = { 1 }, y[] = { 1 }; x == y; // false int x[] = { 0 }, y[] = { 0 }; x == y; // false
- jomamaxx 10y agoThose non equations are perfectly reasonable. One array or object does not equal another, different one. There are definitely gains - I strongly suggest following the 'moral' of the story. At least the === paradigm is fairly consistent and mostly rational.
- alexmorenodev 10y agoWhat the hell am I reading.
- stoic 10y agoWith games like these I feel like we all lose
- jomamaxx 10y agoThis is true. Pun intended!
- Tepix 10y agoIt doesn't seem to work for me on Firefox and Chrome..?
- kakarot 10y agoIt wasn't working on either for me, so I came here to complain, went back and it was suddenly working. Dunno what the issue was but keep trying maybe
- vog 10y agoYes, it seems to take quite a while to start up.
- Spoom 10y agoI had to go into the console and type "return true" for it to start working. I thought it was intentional.
- mk7 10y agoI am so unhappy, because I can not play such games with Java... ;-)
- ninjakeyboard 10y agoI don't exactly know what I did, but it did say that I win.
- okket 10y agoThis page only shows "return true to win" on a white background in Chrome?
- moklick 10y agoseems to be down :/
- tomsmeding 10y agoIt loads eventually
- scrollaway 10y agoDoes it? ReturnTrue:1 Fetch API cannot load https://bigger.alf.nu/db/true/H5VmsyVCBD62113H5Slu https://bigger.alf.nu/db/true/H5VmsyVCBD62113H5Slu. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://alf.nu' http://alf.nu' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
- pointytrees 10y agoit does
- qwertyuiop924 10y agoI already saw this on lobste.rs, but it's still cool. I like ES just fine, but to think we could have had scheme instead. Gee, thanks Netscape: Every time you win, everybody loses.
- ninjakeyboard 10y ago"it's because of you, motherfucker, that we're not all using lisp" @ 5:00 https://www.youtube.com/watch?v=bzkRVzciAZg https://www.youtube.com/watch?v=bzkRVzciAZg
- qwertyuiop924 10y agoNo, that's actually the fault of Netscape. Anyways, that video is awful and totally wrong. Node code can be clean, threaded code can be ugly. Both can be fast, but the perf characteristics are different (for OS threads, anyways).
- apricot 10y agoFind the exact combination of browser/OS that does more than show "return true to win" on a white background to win.
- throwanem 10y agoUse patience.
- wtbob 10y ago> Find the exact combination of browser/OS that does more than show "return true to win" on a white background to win. I see: return true to win (Come back in a few minutes.) What do I win?
- throwanem 10y agoA moment in which to reflect.
- dingo_bat 10y agoI got 'Sorry for the delay.'
- mtrycz 10y agomeeeeeta.
- sirsuki 10y agoTypeError: NetworkError when attempting to fetch resource. Maybe the challenge is to fix HTTP?
- deleted 10y ago[deleted]
- nfriedly 10y agoIt loaded for me eventually. First one is pretty straightforward. After that they seem to require knowledge of JavaScript quirks.
- unsignedqword 10y agoDoes anybody really know why JS's type system was designed the way it was? It seems so out of whack with what people want out of a language, dynamically typed or otherwise.
- throwanem 10y agoIt wasn't; the language was implemented from scratch in ten days.
- mherrmann 10y agoThat explains a lot. Source for others that are interested: https://www.w3.org/community/webed/wiki/A_Short_History_of_JavaScript https://www.w3.org/community/webed/wiki/A_Short_History_of_J...
- deleted 10y ago[deleted]
- bhrgunatha 10y agoObligatory - https://www.destroyallsoftware.com/talks/wat https://www.destroyallsoftware.com/talks/wat
- curveship 10y agoIt's because Eich was told to make JS C-like. In C, an empty array, an empty string, 0, false and null are all the same value: a word with all bits 0. So in JS, those are all are falsy and == to each other.
- jomamaxx 10y agoI wish an empty string was not false. In 'object' terms, an empty string is still a string! It's something. I guess if you think about it from a memory perspective, it's 'nothing'. But since JS is not actually like C, I really wish "" were true.
- 10y ago
- sladix 10y agoDoes someone have a <52 char solution for the counter one ?
- nikital 10y agoOne solution: function(c=1){return function(){return c++}} 44 characters
- curveship 10y ago(x=0)=>()=>++x
- sladix 10y agoHoly crap, that's what I call refactoring !
- posterboy 10y agothat's ascii art, not code
- awalGarg 10y agoYou can save one character by doing this: (x=0)=>_=>++x the underscore is another variable but a single variable does not require parenthesis. So instead of two chars for the two parens, you use a single char for a single letter variable. JS FTW ;)
- deleted 10y ago[deleted]
- Bahamut 10y agoi=>_=>i=-~i
- curveship 10y agoFor the first 5, I've got 2,3,8,14,7. Anybody got tighter solutions?
- esnard 10y agoI got 7 on the third challenge with that solution: transitive([],0,[])
- deleted 10y ago[deleted]
- plopilop 10y agoThe counter one (level 4) can be done with 11 chars. Solution below, found on Reddit[1]. Also, I could not manage fewer than 9 characters for level 3. (Edit: thanks @ensard) Spoiler here: x=>_=>x=-~x And also in this link: [1]: https://www.reddit.com/r/programming/comments/4wd32v/return_true_to_win/d673x90 https://www.reddit.com/r/programming/comments/4wd32v/return_...
- brudgers 10y agoFri Aug 12 14:35:18 UTC 2016: Page had message that the Hacker News 'hug' was likely to affect performance.
- conkrete 10y ago▶ id(true ) // (4 chars) ▷ true You win!
- agentgt 10y agoWhat is with the User/Score/Browser table? I only did like 4 of the tests and that thing popped up. I would finish it but I have some other things to do.
- danielweber 10y agoI can't get past the first test.
- Pfhreak 10y agoLooks like once you successfully score, it shows you how many characters it took others to solve. For example, the first one you can trivially type in true to solve it, with four characters. But it's solvable with only two characters.
- agentgt 10y agoYes but there is no where you can enter your screen name. I should have clarified that in my question because I got down voted for asking this. The whole down voting thing imo really has to go. Just flag answers or up vote. The whole bro intellectual rudeness is sort of off putting.
- CGamesPlay 10y agoMy gosh, this is way harder than the alert(1) series. http://escape.alf.nu http://escape.alf.nu
- billpg 10y agoI typed "true", without the quotes. Did I do it wrong?
- omaranto 10y agoThe link points to a page that only contains the text "return true to win" in large type on a white background. As with most modern art, I don't get it.
- justinlardinois 10y agoAre you browsing with Javascript disabled?
- omaranto 10y agoNo.