I have been receiving a lot of Deppavali wishes, which are unique of its own; either in the design of the greeting or the way it is presented! So I thought, why not produce something different from these wishes. I had been thinking what would befit an unconventional yet interesting Deepavali greeting, which culminated in this:
1)+++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++.+++++++++++++++
++++++++++.+++++++++++++++..+++++++++.>++++++
++++++++++++++++++++++++++.++++++++++++++++++
++++++++++++++++++.++++++++++++++++++++++++++
+++++++..<---------.>----.<++++++.>.+++++++++
++.---.
Here are more greetings that wishes you elaborately!! 
2)+++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++.+++++++++++++++
++++++++++.+++++++++++++++..+++++++++.>++++++
++++++++++++++++++++++++++.++++++++++++++++++
++++++++++++++++++.++++++++++++++++++++++++++
+++++++..<---------.>----.<++++++.>.+++++++++
++.---.>+++++++++++++++++++++++++++++++++...-
.++++++++++++++++++++++++++.-----------------.
3)+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++.
++++++++++++++++++.++++++++++.-----------.>++
++++++++++++++++++++++++++++++.<-------------
--.++++++++++++++++++++++.++++++.>.<---------
-----------.>.+++++++++++++++++++++++++++++++
+++++++++.+++++++++++++++++++++++++.+++++++++
++++++..+++++++++.>++++++++++++++++++++++++++
++++++.<------------------------.<+++++++++++
++.>+++.>.<--------------------.<++++.---.+++
+.---.>+++++++++++++++++++++.+++++++++++++.<-
.>+++.--.>.<---------------------------------
--------------.++++++++++++++++++++++++++++++
+++..<+.>----.<++++++.>.+++++++++++.---.>+...
-.++++++++++++++++++++++++++.----------------
-.
4)+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++.
++++++++++++++++++.++++++++++.-----------.---
---------------------------------------------
------------------------.++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++.+++++++
+++++++++++++++.++++++.----------------------
---------------------------------------------
------------------.++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++.-----
---------------------------------------------
---------------.+++++++++++++++++++++++++++++
+++++++++++.+++++++++++++++++++++++++.+++++++
++++++++..+++++++++.>++++++++++++++++++++++++
++++++++++++++++++++.------------.+++++++++++
+++++++++++++++++++++++++++++++++++++.<------
-.---.++++.---.>+++++++++++++++++++++.+++++++
++++++.<-.>+++.--.>++++++++++++++++++++++++++
++++++.<------------------.<-.>+++.>.<-------
-------------.<+.---..+++++++++.-.-----------
.++++++.-.>----------------------------------
-.+++++++++++++++++++++++++.<++++.>++++++++++
+++++++++++++++++++++..>.<-------------------
--------------.++++++++++++++++++++++++++++++
+++..<--.>----.<++++++.>.+++++++++++.---.>+..
.-.++++++++++++++++++++++++++.---------------
--.
What are those?!! An extremely unintelligible script! Worse than random zeros and ones! Are we impugned with some cryptographical challenge?! May be such thougths are looming into your mind. Don’t worry! I will explicate more on this. Before that, congratulations to those of you who are able to identify that it is just a BrainF*ck code!!! :p
For those of you who don’t know what BrainF*ck is, you can look at the wiki. Briefly, it is a language that you can learn in less than 10 minutes but may take beyond your life time to master!
Try to satiate your curiosity by running the above code with some Brainf*ck interpreter or may be write your own! Writing an interpreter for Brainf*ck is possibly easier job, than say write your first “Hello World” code in it! So many idiosyncrasies, in a simple language!
Ok, the above codes produce respectively the following outputs:
1) Happy Deepavali
2) Happy Deepavali!!! 
Thats my style! I use a lot of smileys while chatting and now with Brainf*ck codes too!
3) Wish You a Happy and Prosperous Deepavali!!! 
4) Wish You a Happy, Prosperous and Pollution-Free Deepavali!!!
Yeah, Pollution-Free that needs to be accentuated more than anything else! Ok, Let us not digress.
Have I succeded in projecting to your mind that I am a BrainF*ck pro?! :p Then lemme extricate myself from your misconception, before you begin to think deep! How do you think I would have done that?! Taking a piece of paper or may be an editor, keeping track of contents of all cells and finally generated the code after a tedious process?! Haha, ok, you have got it right! I did it like that!! 
Hmm, those of you who know me still doubt if I ever did that, for I even haver to a division involving 2 big numbers! Ok, am gonna make a bold confession! I didn’t do like that!
Yeah, I took a different path to doing this. So how would I have done that? Any guesses?!
Ok, here goes the answer. Metaprogramming to the rescue! I wrote a C++ code to search for a Brainf*ck code that will do the job. If this shall make you even more curious, I wouldn’t pester you anymore by keeping you on tenterhooks! Here goes the code:
1 #include <iostream>
2 #include <string>
3 #include <vector>
4 using namespace std;
5
6 string str;
7 int mxSz = 0;
8 string dum;
9
10 void getVal(vector<unsigned char> vec, int cV, int ind)
11 {
12 if(dum.size() > mxSz) return;
13 if(ind == str.size())
14 {
15 cerr << dum << endl << flush;
16 mxSz = dum.size();
17 return;
18 }
19 unsigned char& cnt = vec[cV];
20 string t = dum;
21
22 while(str[ind] > cnt)
23 cnt++, dum += "+";
24 while(str[ind] < cnt)
25 cnt--, dum += ("-");
26 dum += ".";
27
28 getVal(vec, cV, ind + 1);
29
30 if(cV + 1 < vec.size())
31 {
32 dum += ">", getVal(vec, cV + 1, ind + 1);
33 dum.erase(dum.end() - 1);
34 }
35 if(cV >= 1)
36 {
37 dum += "<", getVal(vec, cV - 1, ind + 1);
38 dum.erase(dum.end() - 1);
39 }
40 dum = t;
41 }
42
43 int main()
44 {
45 getline(cin, str);
46 int cnt = 0;
47 for(int i = 0; i < str.size(); ++i)
48 {
49 while(str[i] > cnt)
50 cnt++, printf("+"), ++mxSz;
51 while(str[i] < cnt)
52 cnt--, printf("-"), ++mxSz;
53 printf(".");
54 ++mxSz;
55 }
56 puts("");
57 vector<unsigned char> vec(4);
58 getVal(vec, 0, 0);
59 }
Feel free to use the above code, and if possible give me a credit!
The code is a simple backtracking to generate a Brainf*ck code that would print the input string. I am interested in seeing the shortest possible code. But I make some assumptions:
1. I don’t use any of the Brainf*ck idioms involving operators [ and ]. For example, to copy the value to an adjacent cell etc. That may reduce the size of the code. That is, I consider a subset of Brainf*ck allowing only: +, -, <, >, .
Here after when I reference an arbitaray Brainf*ck code, I am referring to this subset only unless otherwise stated.
Note that ‘,’ used anywhere here is just a separator or a punctuation. It has nothing to do with the Brainf*ck operator “,”.
2. Given that I don’t use any Brainf*ck idioms, another assumption I make is, when you move to a cell, it makes no sense not to use the cell to produce character. That is my program doesn’t search Brainf*ck codes which may have “>>” or “<<" as substrings. But this may be proved wrong; for a long enough input string an optimal code may consist of the above strings. For example, an imput string of the form "*rAZr*", ( * represents an arbitrary sequence of letters ) it may be optimal to have a "<<" after printing AZ. Still I am not sure about whether it is true or not.
More formally:
While searching for an optimal(shortest) Brainf*ck code, is it enough to search across a language that doesn't contain ">>+” or “<<+" ?
where '+' is the regexp operator while '>‘,’>’ belong to the alphabet of the language.
Am not sure if am excluding any other valid Brainf*ck language apart from what I said. If I do, please do tell me.
I have also imposed a restriction on the number of cells that may be used by the output Brainf*ck code, the maximum being set to 4. And my program has output optimal answer for the first 3 strings. For the last one I have put the optimal program I have got till now; it is till running and I will update if I get a more optimal program.
Another important thing you may notice is that the state formulation renders itself to a dynamic programming problem, but I did not memoize the result and am solving the same sub-problem again. But full memoization is impossible considering the prohibitive number of states for using the 4 cells and I have traded it off with liberal use of computing time.
Some note on the Brainf*ck code generated above:
1) Uses 2 cells
2) Uses 3 cells
3) Uses 3 cells
4) Uses 3 cells
The first 3 codes seems to be optimal possible with respect to the language I search. As I said the third code is still running and I am in no way sure about its optimality.
At this point I would like to make a formal definition of a Brainf*ck task of printing a sequence of characters being K-cell optimal. What I mean by a Brainf*ck task being K-cell optimal is that, the shortest possible code has to invariable use K-cells, if it uses (K+i) cells or (K – j) cells for all positive ‘i’ and 1 <= j < K then it cannot be optimal. That is let us define a function F(L) which denotes the length of the shortest possible code "using" exactly L cells. Then F(L) should be ternary searchable and has a minimum value for some 'K'. The question of whether F(L) satisfies this condition is not rigorously clear, though intutition seems to be suggesting that.
Even if it fails to satisfy that condition the definition of "K-cell" optimality can be extended to denote a set of values, using any of which you can get a globally optimal(shortest) code. Obviously it is clear that, if such a set exists then it should be finite, because the number of characters of code using just 1 cell is finite and gives an upper bound on the shortest possible code.
What I mean by "using" L cells is that you should have visited the first L cells.
Note that the formalizations I have made are quite general and doesn't lose their validity in searching for the shortest arbitrary Brainf*ck code.
The reason why I introduce these notions is that, I want to claim that the first 3 programs are respectively, 2-cell, 3-cell and 3-cell optimal with respect to the model I search. No claim yet on the 4th program! Any comments here is welcome.
Now about the shortness of the code. Here goes the length of the program for each of the Brainf*ck codes:
1)275
2)359
3)675
4)1171
It makes no sense to claim that those are the shortest possible codes, Brainf*ck idioms can make it shorter. May be I can say it is the shortest in a model allowing only: +, -, <, >, .
Another interesting question worth investigating will be, how will you come up with a code corresponding to F(L), defined above or at least find the value of F(L) even in my restricted model. Is this problem NP-Hard?! I guess so, but am awaiting a rigorous proof. It is polynomial obviously for L = 1. I guess it can be polynomial for L = 2 also, by some greedy strategy, but am yet to explore on that. What about an arbitray L?
If you have any thought on this please feel free to share!
If you have read this far, thank you very much!
Happy Deepavali!!!