Hacker News new | past | comments | ask | show | jobs | submit login
Infinite Bang Bang (shadabahmed.com)
75 points by shadykiller on Aug 16, 2013 | hide | past | favorite | 47 comments



Doing this too many times is really not a great idea. My machine started grinding to a halt _after_ I had killed the bash that was pumping out all the bangs. Reboot didn't fix it. Deleting my 2 gig ~/.bash_history did :)


haha .. that is so funny :P I did warn, though about not running it for the 7th iteration unless you want 125 million bang bangs in your history file :)


The author's approximation of 125 million bangbangs in the 7th iteration is quite good. The actual number is:

159591041

I wrote a small Python script that allows for further analysis outside the shell:

https://github.com/vog/bangbang


That's prime. Can someone figure out what's actually going on here? Prime numbers with that many digits shouldn't pop up by pure chance...

I'm sure you all caught this, but the first 3 in the sequence are also prime.


I'm too busy to check but I'd bet money that it's a Mersenne prime. The series looks exponential (like 2^n) and it's not hard to imagine that fenceposting (±1) led to each member in the series being (2^n)-1 - which is the form for Mersenne primes.

Edit: Dang, I was wrong. ;)


Nope.

http://www.bigprimes.net/cruncher/159591041/

Don't take up gambling. ;)


Awesome . .even I was close to 150 million but never the exact number anyway .. thanks for this


Do you have the exact number for the 8th iteration ?


Unfortunately, no.

The script actually calculates strings, then counts the bangbangs. The 7th iteration took about 4 GiB RAM (temporarily, and 2 GiB in the end). Using this approach, I don't think there's enough RAM for the 8th iteration on this planet.

The algorithm would have to be optimized quite a lot before it could calculate the exact 8th value.


Okay, I finally found a way that gets us one more iteration. The exact next value is:

168668479408755201

Assuming your approximation "7 Quadrillion" means 7e15 (rather than 7e24 [1]), this is about 24 times as much.

[1] http://en.wikipedia.org/wiki/Quadrillion


I am still skeptical for this . . the basic approximation formula gives a ballpark .. and when I put 159 million in the formula it gives me 12640500079500000 which is 12 quadrillion ... http://www.tools4noobs.com/online_tools/number_spell_words/

Reason I say this is - let's assume all 159 million bangs are expanded then 159*159 millions = 25 quadrillion


Sorry, this was a mistake. The correct number is:

16866847940875521

which is just 2.4 times as much as your approximation.

It would be nice if somebody could confirm my numbers indepdently.


Yes . .16 quadrillion seems closer


The exact number for the 9th iteration is 189345699699803478502456213711361.

Here is an algorithm for computing them efficiently: https://gist.github.com/robinhouston/6251775


Trying to figure out a mathematical representation of this sequence...

I noticed that different patterns emerge when you subtract 1 from each value in the sequence. From there we get:

0

1

2

4

16

160

15680

159591040

16866847940875520

Each (excluding 0 and 1) is a multiple of the previous term:

1

2 = 1 * 2

4 = 2 * 2

16 = 4 * 4

160 = 16 * 10

15680 = 160 * 98

159591040 = 15680 * 10178

16866847940875520 = 159591040 * 105687938

Anything ring a bell? Notice any other patterns?


Also, subtracting 2 from each of those numbers produces a similar pattern:

2 - 2 = 0

2 - 2 = 0

4 - 2 = 2

10 - 2 = 8 = 2 * 4

98 - 2 = 96 = 8 * 12

10178 - 2 = 10176 = 96 * 106

105687938 - 2 = 105687936 = 10176 * 10386


Should this series be added to the OEIS?

https://oeis.org/search?q=1%2C2%2C3%2C5%2C17%2C161%2C15681


I'm about to add it. For this, I had to register for an account, confirmed my email address, but I'm still waiting for the final account creation.


I finally added this sequence as A228162. Here is the draft that waits for review:

https://oeis.org/draft/A228162


I think that the author is a little confused, the linked image in not the original XKCD (http://xkcd.com/149/)


Not confused .. I had initially only had the image and not XKCD link until someone asked me to credit them .. I added the link without noticing the text. .removed the link now :)


I mentioned it because I've seen that xkcd and didn't learn about the bang syntax until today. Great Article.


Thanks :) This is my first article to break into HN top 10 and also got me max upvotes


There is an upvote limit?


I think he meant it was his highest score to date.


I used to use a password that ended in !! before I knew about the command, before I even seriously used Linux. It caused problems setting up MySQL and even caused issues for a domain host while transferring a domain of mine. I don't use that password anymore :)


But using things that break other things from time to time is probably still a good idea to find software defects. I used to have a user on my machine whose name (and thus profile folder) contained a non-Latin-1 letter and a space.


Further analysis by Robin Houston:

https://news.ycombinator.com/item?id=6227115

Newly registered OEIS sequence:

https://oeis.org/A228162


Alas! A no-go in fish:

    ~ !!
    fish: Unknown command “!!”



That seeems... silly. `sudo !!` feels vastly superior to "Up, Home, `sudo `"

Mostly because !! is right there and Up+Home are over there.


This is probably the only worst thing I've encountered since switching my desktop to fish. Can you write a fish function and name it !!?


Yes .. only sh and bash ...in zsh, the series does grow but not so explosively


Bash history completion is sometimes useful (!mysql) but mostly annoying (using ! somewhere mid-sentence)

!! is pointless because up arrow, come on.


!! is not at all pointless, "sudo !!" is much easier that Up, Ctrl-a, "sudo ".


I have alt-s in my zsh which does zle beginning-of-line; zle -U "sudo "

Also it's up, home, "sudo "


I may have to steal that alias, good tip.

Ctrl-a/Ctrl-e are equivalent to Home/End (unless you're inside a screen session, which was a terrible choice of binding on their part).


Note that these aren't bash things. They're the emacs bindings for readline, so they work with anything that uses readline (like the mysql client).

You can set them to the vi ones instead with:

    set -o vi
..and they do work with screen ;-) (0 for start, $ for end)


> escape \000\040

in my screenrc changes this to 'CTRL+spacebar', which I find much more sensible.


or sudo ESC-. which inserts the last word from the last command.


awesome!


This goes in the same bucket of fun that contains

:(){ :|:& };:

Don't run that on a shell unless you enjoy having to physically reboot servers.


What does it do? Definitely not going to try it.



It makes a function called :, which calls itself. More or less.


Pipes itself into a new instance of itself every time, thus spawning processes geometrically. Hence, Fork Bomb.


It makes a function called : which spawns processes, and each of those processes spawns more processes calling itself.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: