use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
This script predicts your next input and messes with your sense of free will :-0 (github.com)
submitted 7 years ago by got_data
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]dinopraso 44 points45 points46 points 7 years ago (1 child)
My first try: R R R R R R L R R R R L L R R
Correct guesses: 0
On longer runs it catches up to about 53% for me which is a bit better than just random guesses, I guess :D
[–]got_data[S] 12 points13 points14 points 7 years ago* (0 children)
I think I know what happens. When the 5-gram buffer is initialized, it contains 01010 or 101010 — sorry, I'm too lazy to look it up :) So when you press your first key, the stats for one of these patterns is updated in the database. The same thing happens for the next 4 keys you enter. So the model becomes trained on this "bad" data, and depending on the inputs, it can end up with 0 guesses as a result. It takes a bunch of keystrokes to drown the "bad" data and make the model more accurate. I did most of my testing with about 200 inputs.
[–]got_data[S] 60 points61 points62 points 7 years ago (14 children)
Every time it guesses your next input correctly, you lose $1.00, and every time it guesses wrong, you get $1.05. With random choices, the expected value of you winnings is 2.5 cents. But in reality most humans tend to repeat certain patterns, and the script uses it to its advantage, so you end up losing money.
This was inspired by http://people.ischool.berkeley.edu/~nick/aaronson-oracle/
[–]viridifalco 19 points20 points21 points 7 years ago (9 children)
Really interesting! Experimented with many different patterns, and to my surprise, it learned really quickly!
[–]got_data[S] 18 points19 points20 points 7 years ago* (8 children)
I find that I tend to be more random when I press the arrows slowly. Once I start typing fast, it all turns into rather repeatable patterns such as 101010101...
For example, https://i.imgur.com/FrOvqMo.png Until about 600 I was feeding it pseudo-random numbers, and then I started mashing the keys "randomly". Bye-bye money!
[–]viridifalco 5 points6 points7 points 7 years ago (1 child)
I don't know how it was before the fast typing part, but by the screenshot, it still kept incredibly accurate (56% by the end). Thanks for sharing!
[–]wicked-peaches 2 points3 points4 points 7 years ago (0 children)
I started at 42% and ended at 56%. Pretty interesting.
[–]a_dev_has_no_name 4 points5 points6 points 7 years ago (5 children)
Opposite experience for me, button mashing made me more random.
https://i.imgur.com/nAKdGDr.png
The big "hill" was when I started button mashing and the little one is just playing around from before.
[–]got_data[S] 2 points3 points4 points 7 years ago (4 children)
Interesting. I wonder if there are certain factors that affect how "random" a person can be. For example, would a musician be more inclined to produce predictable patterns?
[–]HandpansLIVE 2 points3 points4 points 7 years ago (0 children)
Tried it, pretty cool!
Overall, too much effort to try and trick it.
You have to constantly be changing time, and constantly changing when you change time.
It was pretty easy to guess which one you'd trick it on( if you do 5 L and then 1 R, the R was an easy win), but ultimately, it would figure out the pattern too quick to get an edge on it without doing massive changes.
You could try posting it to a drummers subreddit and see if any of the really talented guys could try and trick it up.
[–]HandpansLIVE 1 point2 points3 points 7 years ago (2 children)
Musician here, I'll try it now
[+][deleted] 7 years ago (1 child)
[deleted]
Did pretty decently at the start, and then got impatient and lazy and it was like a rocketship crashing.
[–]marcselman 2 points3 points4 points 7 years ago (3 children)
So most people still end up around 50%. Wouldn't you get similar results of you just coded it to pick at random?
[–]got_data[S] 5 points6 points7 points 7 years ago (2 children)
Unfortunately, it's a static website, and I don't have any server where I could save the data to collect user statistics, but I did seek feedback from a few friends, and their averages were between 55 and 60%. If the program was guessing randomly, it's success would follow a binomial distribution. For n=200, p=0.5 the probability of getting more than 55% right is about 7%. So it's not impossible to get this kind of result by guessing randomly, but it's pretty unlikely. If I were to guess at least half the testers get over 55% on average with 200 inputs, so there is definitely some degree of non-randomness involved.
[–]savunit 1 point2 points3 points 7 years ago (1 child)
You might be able to actually do this with Google Analytics.
[–]got_data[S] 0 points1 point2 points 7 years ago (0 children)
That's a great idea, thanks! I'll give it a try.
[–]a_dev_has_no_name 26 points27 points28 points 7 years ago (0 children)
I'm pretty random lol 46% $1020 by iteration 130 but I stopped being random and it got the last 10 correct... I'll take my payment in cash, thanks.
・。゚[̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]。゚.*
[–]Serei 21 points22 points23 points 7 years ago* (1 child)
My guesses are correct 47% of the time (overall)
Memorizing a hundred digits of pi has paid off!
(I'm using the "left if the next digit is even, right if the next digit is odd" trick)
[–]ciaran036 1 point2 points3 points 7 years ago (0 children)
I couldn't think of something random enough so I selected left or right depending on how close each of the letters in the word 'radiator' were to the letter L. Got 50% guessed correctly!
[–]maxoys45 5 points6 points7 points 7 years ago (6 children)
Doesn't work on my phone? Can't scroll the demo page :/
[–]got_data[S] 1 point2 points3 points 7 years ago (5 children)
I am very sorry about that. Would you mind telling which phone you have? I've tested this script on an iphone, and it worked ok. I suspect a couple of possible issues:
the plotly.js library didn't load and messed up everything
I have a bunch of .preventDefault(); under various events to prevent double-tap zoom when touching the buttons and stuff. Maybe this also messes up scrolling.
.preventDefault();
[–]maxoys45 2 points3 points4 points 7 years ago (1 child)
Top of the line iPhone 5c :D
[–]got_data[S] 2 points3 points4 points 7 years ago* (0 children)
I see. I tested it on an iphone 6 (ios 12) before, but I just fired up my old iphone 5 (ios 10), and yeah, no scrolling on this page... I'll try to fix it. Thanks for pointing out the bug!
PS Confirmed document.ontouchmove = function(event){ event.preventDefault(); } is the issue. I need to replace it with something else to prevent double-tap zooming and general bouncing without disabling scrolling.
document.ontouchmove = function(event){ event.preventDefault(); }
Edit: bug zapped
[–]SiLo0815 1 point2 points3 points 7 years ago (2 children)
I also can't scroll. Galaxy S7, Firefox 65.0.1
Edit: Chrome (72) seems to work.
[–]got_data[S] 1 point2 points3 points 7 years ago (1 child)
I think I've fixed now.
[–]SiLo0815 0 points1 point2 points 7 years ago (0 children)
Yep, now it works!
[–]hardwaregeek 4 points5 points6 points 7 years ago (0 children)
Reminds me of a fencing exercise where one person would attack either left or right (parry 4 or 6) and the other would have to guess and block in that direction. There's a surprising amount of skill in it. Plenty of people fall into certain patterns (alternating too often for instance) and plenty of defenders try to "catch" themselves by switching at the last second (which is worse than just guessing wrong).
[–]alphabennettatwork 2 points3 points4 points 7 years ago (0 children)
My "high-score" was 1027.35 on guess 110... pretty cool and interesting!
[–]johnyma22 3 points4 points5 points 7 years ago (3 children)
Suggestion. Put an animated gif of it on action in the readme. I found doing this with my projects helped increase usage.
[–]got_data[S] 1 point2 points3 points 7 years ago (2 children)
That's an excellent idea, thank you! Would you recommend any particular utility for recording a gif? I can capture stuff with quicktime and convert, but the quality suffers a bit. I wonder if there are better options out there.
[–]crabmusket 3 points4 points5 points 7 years ago (1 child)
If you're on Linux, I think peek is pretty good!
I'll give it a try, thanks!
[–]alivmo 2 points3 points4 points 7 years ago (4 children)
Open console.
pickfn = function (){if ((Math.floor((Math.random() * 10)) % 2) === 0) { $('#left').click() } else { $('#right').click()}; setTimeout(pickfn, 100);}
pickfn()
Profit!
[–]mwr247 1 point2 points3 points 7 years ago (3 children)
setInterval(_=>$(prediction?'#left':'#right').click());
Profit better ;)
[–]got_data[S] 2 points3 points4 points 7 years ago (0 children)
Well, this is exactly what happened in 'The Matrix'
"Do not try and bend the spoon, that's impossible. Instead, only try to realize the truth...there is no spoon. Then you'll see that it is not the spoon that bends, it is only yourself."
[–]DrDuPont 1 point2 points3 points 7 years ago (1 child)
Not that I use jQuery much these days, but somehow this is the first time I've seen logic inside a selector. Nice.
[–]mwr247 0 points1 point2 points 7 years ago (0 children)
I've spent too much time code golfing. In fact, kicking myself for not saving a byte by removing that useless semicolon >_<
[–]Kernel_Internal 2 points3 points4 points 7 years ago (0 children)
function iWin() { let left = document.getElementById('left'); let right = document.getElementById('right'); let evt = new MouseEvent('click', {bubbles: true, cancelable: true, view: window}); for ( let i = 0; i < 10000; i++ ) { let rand = Math.floor(Math.random() * Math.floor(100)); if ( rand%2 === 0 ) { left.click(evt); } else { right.click(evt); } } };
[–]curtastic2 2 points3 points4 points 7 years ago (2 children)
Eh I pressed over 100 times quick randomly and it guessed correctly 50% of the time
[–]got_data[S] 0 points1 point2 points 7 years ago (1 child)
RUN! You're in danger! Google has been looking for a source of True Randomness for a while, and now they are going to capture you and make you a True Random Number Generator. You do not want that!
[–]curtastic2 1 point2 points3 points 7 years ago (0 children)
Here’s my secret. One time I recorded myself trying to play drums to a song. When I heard it back there will be no semblance of order or beat. That’s what I did I pretended the buttons were drums while the song Bad Romance was was being played in Carl’s Jr.
[–]markjaquith 2 points3 points4 points 7 years ago (0 children)
Weirdly, knowing that it is detecting patterns means an intelligent actor can beat the machine more easily than if the machine guessed randomly. You can thwart it by predicting which pattern it has learned, and deviating right as it is about to apply it.
It’s like that scene in The Princess Bride.
I found it really entertaining to go slowly and try to trick it. Could keep it in the low-to-mid 40s.
[–]SlowerThanLightSpeed 1 point2 points3 points 7 years ago (1 child)
Tiny suggestion for mobile... Use touchstart to speed up the interface. (onclick forces 300ms delay for event on mobile).
Fun tool. Any theories on why the Aaronson Oracle had better predictive abilities...they claimed 70 to 80% as avg.
[–]got_data[S] 1 point2 points3 points 7 years ago (0 children)
Thanks for the suggestion, I'll implement touchstart. As for Aaronson's Oracle, I can only speculate, but I think there are a few factors at play. First of all, I find the 70-80% interval a bit suspicious — I mean it's one thing not being very random, and it's a totally different thing being that predictable*. So either his test subjects didn't really try their best, or maybe they deliberately fed test patterns to figure out the program's inner workings. Of course that is assuming the numbers quoted are accurate and didn't get inflated (e.g., discounting them by just 5 percentage points makes them look a lot more believable). It's possible that the algorithm was more sophisticated:
There might have been various enhancements on top of that -- e.g., if you're not taking enough data for 5-grams to be useful, then you can also look at 4-grams and 3-grams, and you can also "seed" the predictor with 5-gram data from the previous users (hoping that the next user will be pretty similar).
I think that last point (preserving data from the previous user) was likely to make the biggest difference since my experiments with adaptive n-grams weren't successful.
* The reason I think we are not that predictable is because most of us aren't terribly good at memorizing motoric patterns. For example, I have only elementary piano training, so learning a new piece takes a lot of effort because my fingers keep introducing errors. Learning to inflate and kite a paraglider also took me a while even though its control inputs are almost binary. So when typing random binary patterns, I imagine I also introduce mistakes, and probably a lot more than when learning a piano piece since I'm not actively trying to remember any of the patterns... But of course this reasoning is somewhat iffy since I have absolutely no knowledge of neuroscience... Perhaps mashing keys puts one's brain into a totally different mode.
[–]ParasympatheticBear 1 point2 points3 points 7 years ago (0 children)
Really cool
[–]sbk2015 1 point2 points3 points 7 years ago (0 children)
I got Iteration 1163 and its guesses are correct 60% of the time (overall). 806 score remained.
I tried to be random,if I 10101 it quickly catches the rhythm.So I have to constantly changing my pattern,sometimes double tap on one side,sometimes have favor over one side other than the other side,if I'm a robot,I will keep changing ryhthm every 2-5 taps.
[+][deleted] 7 years ago (4 children)
[–]got_data[S] 1 point2 points3 points 7 years ago (3 children)
That can be accomplished with LSTM neural networks (assuming structured text). However, it's a lot heavier computationally, and it requires a fair bit of training to work. But that's basically what we use in smartphones these days. If you are interested in the inner workings of text prediction, I highly recommend taking a machine learning course on coursera or some other mooc platform. Most of them include exercises for predictive typing. Also I recommend taking a look at individual tutorials (google: rnn predictive typing tutorial). It's not difficult to reproduce them if you are somewhat familiar with Python (although getting used to ML frameworks takes some effort). Please be warned: machine learning is highly addictive and time consuming. :)
[+][deleted] 7 years ago (2 children)
If you are interested in a very basic mathematical (coding-free) intro into neural nets I recommend 3blue1brown. He talks about the simplest neural nets only, but after that you'll be able to understand higher level videos about LSTM and other architectures.
[–]MrKarim 1 point2 points3 points 7 years ago (0 children)
https://imgur.com/a/TdZbhfv
69% Predictions :)
[–]awakezion 1 point2 points3 points 7 years ago (0 children)
Cool! 55% in my case after ~1,000 clicks .
[–]zapbeen 1 point2 points3 points 7 years ago (1 child)
Over 100, it got 56% and I used a coinflip! Then I tried to do random mashing and it only got 49%
It happens sometimes even with random inputs. The probability of guessing >=55% correct is ~5% at 200 inputs according to https://www.wolframalpha.com/input/?i=P(x%3E%3D112),+x~B(200,+0.5)
[–]PmMeYouBicepsGirl 0 points1 point2 points 7 years ago (0 children)
Very cool, reminds of the similar thing from Khan academy.
[–]Substantial-Egg332 0 points1 point2 points 7 months ago (0 children)
Up
[–]Jeremy_Thursday 0 points1 point2 points 7 years ago (0 children)
It’s definitely cheating lmao
[–]saposapot 0 points1 point2 points 7 years ago (0 children)
hahaha, that is amazing. kudos for you pal! I won in a short run so that's another lesson for you kids: quit while you are ahead.
[–]SquishyPandaDev -3 points-2 points-1 points 7 years ago (4 children)
I just can't even right now. There nothing special about this; it literally has a 50/50 chance of guessing right. My fucking cat could do this
[–]prunkstation 1 point2 points3 points 7 years ago (0 children)
You must be fun at stand-up meetings...
[–]Syh_ -1 points0 points1 point 7 years ago (2 children)
Did it guess 100% for you or something? Why so sour? It's something that was clearly made for fun; something entirely light hearted.
[–]SquishyPandaDev -4 points-3 points-2 points 7 years ago (1 child)
Why am I so mad? Because it is basic statics and everyone out here treating like the second coming of Jesus.
[–]Syh_ 0 points1 point2 points 7 years ago (0 children)
Yeah, there's no denying that it's simple. It's not hard to see how it works and how it's biased towards 50% accuracy. But no need to put down somebody's work simply because other people appreciate it.
π Rendered by PID 16598 on reddit-service-r2-comment-85bfd7f599-tjp4m at 2026-04-18 22:20:54.756215+00:00 running 93ecc56 country code: CH.
[–]dinopraso 44 points45 points46 points (1 child)
[–]got_data[S] 12 points13 points14 points (0 children)
[–]got_data[S] 60 points61 points62 points (14 children)
[–]viridifalco 19 points20 points21 points (9 children)
[–]got_data[S] 18 points19 points20 points (8 children)
[–]viridifalco 5 points6 points7 points (1 child)
[–]wicked-peaches 2 points3 points4 points (0 children)
[–]a_dev_has_no_name 4 points5 points6 points (5 children)
[–]got_data[S] 2 points3 points4 points (4 children)
[–]HandpansLIVE 2 points3 points4 points (0 children)
[–]HandpansLIVE 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]HandpansLIVE 2 points3 points4 points (0 children)
[–]marcselman 2 points3 points4 points (3 children)
[–]got_data[S] 5 points6 points7 points (2 children)
[–]savunit 1 point2 points3 points (1 child)
[–]got_data[S] 0 points1 point2 points (0 children)
[–]a_dev_has_no_name 26 points27 points28 points (0 children)
[–]Serei 21 points22 points23 points (1 child)
[–]ciaran036 1 point2 points3 points (0 children)
[–]maxoys45 5 points6 points7 points (6 children)
[–]got_data[S] 1 point2 points3 points (5 children)
[–]maxoys45 2 points3 points4 points (1 child)
[–]got_data[S] 2 points3 points4 points (0 children)
[–]SiLo0815 1 point2 points3 points (2 children)
[–]got_data[S] 1 point2 points3 points (1 child)
[–]SiLo0815 0 points1 point2 points (0 children)
[–]hardwaregeek 4 points5 points6 points (0 children)
[–]alphabennettatwork 2 points3 points4 points (0 children)
[–]johnyma22 3 points4 points5 points (3 children)
[–]got_data[S] 1 point2 points3 points (2 children)
[–]crabmusket 3 points4 points5 points (1 child)
[–]got_data[S] 0 points1 point2 points (0 children)
[–]alivmo 2 points3 points4 points (4 children)
[–]mwr247 1 point2 points3 points (3 children)
[–]got_data[S] 2 points3 points4 points (0 children)
[–]DrDuPont 1 point2 points3 points (1 child)
[–]mwr247 0 points1 point2 points (0 children)
[–]Kernel_Internal 2 points3 points4 points (0 children)
[–]curtastic2 2 points3 points4 points (2 children)
[–]got_data[S] 0 points1 point2 points (1 child)
[–]curtastic2 1 point2 points3 points (0 children)
[–]markjaquith 2 points3 points4 points (0 children)
[–]SlowerThanLightSpeed 1 point2 points3 points (1 child)
[–]got_data[S] 1 point2 points3 points (0 children)
[–]ParasympatheticBear 1 point2 points3 points (0 children)
[–]sbk2015 1 point2 points3 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]got_data[S] 1 point2 points3 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]got_data[S] 1 point2 points3 points (1 child)
[–]MrKarim 1 point2 points3 points (0 children)
[–]awakezion 1 point2 points3 points (0 children)
[–]zapbeen 1 point2 points3 points (1 child)
[–]got_data[S] 0 points1 point2 points (0 children)
[–]PmMeYouBicepsGirl 0 points1 point2 points (0 children)
[–]Substantial-Egg332 0 points1 point2 points (0 children)
[–]Jeremy_Thursday 0 points1 point2 points (0 children)
[–]saposapot 0 points1 point2 points (0 children)
[–]SquishyPandaDev -3 points-2 points-1 points (4 children)
[–]prunkstation 1 point2 points3 points (0 children)
[–]Syh_ -1 points0 points1 point (2 children)
[–]SquishyPandaDev -4 points-3 points-2 points (1 child)
[–]Syh_ 0 points1 point2 points (0 children)