
Infinite Bang Bang - shadykiller
http://shadabahmed.com/blog/2013/08/16/bang-bang
======
ent
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 :)

~~~
shadykiller
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 :)

------
vog
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](https://github.com/vog/bangbang)

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

~~~
vog
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.

~~~
vog
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](http://en.wikipedia.org/wiki/Quadrillion)

~~~
vog
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.

~~~
shadykiller
Yes . .16 quadrillion seems closer

------
jamesmaniscalco
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?

~~~
jamesmaniscalco
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

------
zeckalpha
Should this series be added to the OEIS?

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

~~~
vog
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.

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

[https://oeis.org/draft/A228162](https://oeis.org/draft/A228162)

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

~~~
shadykiller
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 :)

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

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

~~~
zeckalpha
There is an upvote limit?

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

------
jasonkostempski
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 :)

~~~
ygra
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.

------
vog
Further analysis by Robin Houston:

[https://news.ycombinator.com/item?id=6227115](https://news.ycombinator.com/item?id=6227115)

Newly registered OEIS sequence:

[https://oeis.org/A228162](https://oeis.org/A228162)

------
cskau
Alas! A no-go in fish:

    
    
        ~ !!
        fish: Unknown command “!!”

~~~
sikhnerd
This is covered in the faq:
[http://ridiculousfish.com/shell/user_doc/html/faq.html#faq-h...](http://ridiculousfish.com/shell/user_doc/html/faq.html#faq-
history)

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

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

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

!! is pointless because up arrow, come on.

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

~~~
guard-of-terra
I have alt-s in my zsh which does _zle beginning-of-line; zle -U "sudo "_

Also it's up, home, "sudo "

~~~
dr4g0n
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).

~~~
phaemon
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)

------
suhail_ansari
awesome!

------
madaxe
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.

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

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

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

