text:
Q: Time complexity of a sorting algorithm The two programs below get n integers from file and calculates the sum of ath to bth integers q(number of question) times. I think the upper program has worse time complexity than the lower, but I'm having problems calculating the time complexity of these two algorithms.
[input sample]
5 3
5 4 3 2 1
2 3
3 4
2 4

[output sample]
7
5
9

Program 1:
#include <stdio.h>

FILE *in=fopen("input.txt","r");
FILE *out=fopen("output.txt","w");

int n,q,a,b,sum;
int data[1000];

int main()
    int i,j;
    fscanf(in,"%d%d",&n,&q);
    for(i=1;i<=n;i++) fscanf(in,"%d",&data[i]);
    for i=0;i<q;i++)
    {
        fscanf(in,"%d%d",&a,&b);
        sum=0;
        for(j=a;j<=b;j++) sum+=data[j];
        fprintf(out,"%d\n",sum);
    }
    return 0;
}

Program 2:
#include <stdio.h>

FILE *in=fopen("input.txt","r");
FILE *out=fopen("output.txt","w");

int n,q,a,b;
int data[1000];
int sum[1000];

int main()
{
    int i,j;
    fscanf(in,"%d%d",&n,&q);
    for(i=1;i<=n;i++) fscanf(in,"%d",&data[i]);
    for(i=1;i<=n;i++) sum[i]=sum[i-1]+data[i];
    for(i=0;i<q;i++)
    {
        fscanf(in,"%d%d",&a,&b);
        fprintf(out,"%d\n",sum[b]-sum[a-1]);
    }
    return 0;
}

The programs below gets n integers from 1 to m and sorts them. Again, I cannot calculate the time complexity.
[input sample]
5 5
2 1 3 4 5

[output sample]
1 2 3 4 5

Program:
#include <stdio.h>
FILE *in=fopen("input.txt","r")
FILE *out=fopen("output.txt","w")

int n,m;
int data[1000];
int count[1000];

int main()
{
    int i,j;
    fscanf(in,"%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        fscanf(in,"%d",&data[i]);
        count[data[i]]++
    }
    for(i=1;i<=m;i++)
    {
        for(j=0;j<count[i];j++) fprintf(out,"%d ",i);
    }
    return 0;
}

It's ironic(or not) that I cannot calculate the time complexity of my own algorithms, but I have passions to learn, so please programming gurus, help me!

A: What you need to do is pay attention to the loops, specifically how many times the loops repeat, and how much time is spent inside the loops.  You need to multiple the number of times the outer loop repeats by the amount of time it takes inside the loop... if there is a inner loop, you multiply the number of repititions of the outer loop by the number of repititions of the inner loop, for example, to get the time complexity.
In your first program, you have one loop that takes O(n) time followed by a loop that takes O(q*(b-a)) time... it isn't exactly clear to me what b and a represent... but if you can bound b-a (let's say, you know that b-a < n), then you can express this more simply (e.g. if b-a < n, then you would say it was O(q*n)). The overall runtime would be the sum of those two terms, or, if one term is always bigger than the other, use the bigger term.
In the second program, you have two loops, each taking O(n) time, followed by a loop that takes O(q) time. So, the overall runtime is O(n+q). Note that if one term dominates the other, you can drop the term that is smaller. Even without knowing the value of (b-a), it is already apparent that this is better than the first one.
In the third program, the overall runtime is O(n+m), because you have one loop that takes O(n) time followed by a loop that takes O(m) time. If you know that m < n or vice-versa, you can simplify the expression by dropping the dominating term. If they can vary so that you don't know that one dominates the other, then writing it out as O(m+n) is the best you can do in terms of stating the time-complexity.
I should also point out that even if a loop is performed more than once, but it is performed a fixed number of times (e.g.  in program 2, you have two loops that take O(n) time), it doesn't affect the time-complexity, because O(2n) is the same as O(n); in other words, constant factors don't matter in big-Oh complexity analysis. Also, if you have an inner loop that varies in terms of the number of times it is executed, if you are performing "worst-case" complexity analysis, you only need to know the worst possible value it can have.
For example, consider the following loop:

for (int i = 0; i < n; i++ ){
   for (int j = i+1; j < n; j++ ){
       // something taking O(1) time
   }
}

The loop above takes O(n^2) time, even though not all the inner loops will take O(n) time.
I would also like to add that you should do a better job of formatting your program. Even though braces are not strictly required when an if/for/while statement only has one statement in the body, it is much more readable to use the braces anyway, and to use a newline. For example, it is much more readable if you write:

for (int i=1; i<=n; i++) {
    sum[i]=sum[i-1]+data[i];
}

Than writing it as for (i=1; i<=n; i++) sum[i]=sum[i-1]+data[i];. Also, I should point out that even though you have tagged this question as C++, you are using C-like code... in C++, you can declare variables in the initialization of the for-loop (I suggest you do so). Also, in C++, the iostreams library (std::cin, std::cout, std::fstream, std::ostringstream, std::istringstream, etc.) are preferred over C FILE* objects.
You may also be interested in the following resource:

*

*Stanford University: Analysis of Algorithms from Google Code University


text:
Q: Looper.prepare() with AlertDialog I would like to insert a time counter inside a game. If the time is 0, there would be an AlertDialog which tells the user the time is out, and goes back to the previous Activity. Here is the method (it is inside a class which extends a SurfaceView):
public void showTime(){
    time--;
    Log.i("GameView time", "" + time);
    if (time <= 0){
        Log.i("gameview time","time out");
        gameTimer.setRunning(false);
        AlertDialog.Builder alt_bld = new AlertDialog.Builder(this.getContext());
        AlertDialog alert = alt_bld.create();
        alert.setTitle("Time is out. You lose.");
        alert.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                main.onBackPressed();
            }});
        alert.show();
    }
}

The GameTimer class is a Thread:
public class GameTimer extends Thread{

private GameView gameView;
private boolean run;

public GameTimer(GameView gameView){
    this.gameView = gameView;
}

public void setRunning(boolean value){
    this.run = value;
}

public void run(){
             Looper.prepare();
    while (run){
        try {
            gameView.showTime();
            sleep(1000);
        } catch (Exception e){
            e.printStackTrace();
        }
    }
            Looper.loop();
}

}
The AlertDialog appears, but the app crashes, with the message: Only the original thread that created a view hierarchy can touch views. But this is the thread which created... Where's the problem?

A: Do this using Handler or Use
this.runOnUiThread(new Runnable() {

        public void run() {
            // TODO Auto-generated method stub

        }
    });

The error itself tells the whole story.
And if you are not in Activity/ View's Parent class then use some callback Mechnasim.
This will help you to resolve your issue.
Cheers.

A: Judging by the error you are getting, you are passing your View object into the Thread class constructor from somewhere else and then trying to use it's method to create an AlertDialog. Unfortunately this will not work.
You need to use Handler to send back the message(in your case, time = 0) from your thread to your View class , where you have defined the showTime() method.
Define the Handler and then override the handleMesage() method to call your showTime() methid.
Below link can help you get started.
http://developer.android.com/reference/android/os/Handler.html

redpajama_set_name: RedPajamaStackExchange


text:
Q: Android Beam: How to Beam Contents being Downloaded I am developing an applicaiton which supports content delivery via Android Beam (to be more accurate, supporting an NFC-initiated content transfer using Bluetooth). I'm using the well-known APIs available through NfcAdapter class, nameley,
nfcAdapter.setBeamPushUrisCallback(new NfcAdapter.CreateBeamUrisCallback() {

                @Override
                public Uri[] createBeamUris(NfcEvent event) {
                    if (singleItemToTransfer()) {
                        if (item.getLocalPath() != null) {
                            File file = new File(item.getLocalPath());
                            return new Uri[] { Uri.fromFile(file) };
                        } else {
                            // Download the content & pass the handle
                            // for the content being downloaded
                        }
                    }
                }

}, this);

Now the question is how Android framework will handle scenarios, where the content to be transferred is currently not available and yet needs to be downloaded first and then transferred. For example, only the preview of a photo is available and upon selecting the preview, the app downlads the content first and then transfers via Android Beam (Bluetooth, for instance). I searched arround and found out that there are ways to obtain a handle to the files currently being downloaded by the Android DownloadManager. For example, there is an interesting post here. Basically, the DownloadManager class stores a list of http downloads initiated and their associated status. It was suggested that we filter downloads out based on whether the downloads are 'RUNNING', 'PENDING', 'PAUSED' and so on. This list can be read into a cursor and one of the columns of the result is 'COLUMN_URI', which is the url from where the file is being downloaded.
Regaridng the aforementioned solution, there is a concern, though: What if the content is in the Cloud? Say, Google Drive? I search further and came across with many posts, e.g., here. Apparently, the download part is still in place. The content needs to be first downloaded before being transferred.
Apart from the above question, I also wondered how Android Beam would act if we are first aiming at downloading the content and then returning the URI of the file whose download is now complete. In order to test, I created a mock code, like Thread.sleep(_some_time_); and then passed the URI of an actual within createBeamUris() call. In this case, Android Beam prompts the user on detecting the other device in the field and then waits for the amount of time introduced above and then issues "Tap to Beam", which in general gives an extremely terrible user experience (for example, the other device's screen gets locked and NFC goes OFF). Subsequently, I thought about passing a URI for the file being downloaded and then transfer the content while it is being downloaded! I am not sure how this will be handled. I am afraid that modifying how Android Beam works is the only option. Any hints is highly appreciated!
If you believe I have missed something, kindly let me know and I will update the post.

A: I eventually decided to change the Android framework and got it working.


text:
Q: References for the representation theory of some algebraic groups I'm interested in learning more about the representation theory of the group schemes $SL_2$, $GL_2$ and $\mathbb{G}_m$ (as group schemes over the rationals, say) - specifically, the structure of all irreducible representations.
There is a lot of literature out there about the irrepucible representations of specific points of these groups e.g. $SL_2(\mathbb{R})$, $GL_2 (\mathbb{C})$ using the the theory of Lie groups/differential geometry etc. I would like to know:
1) What are some especially good references (books/articles/notes) about the representation theory of these algebraic groups and the structure of their irreducible reps?
2) In particular, are there any sources which deal with the representation theory of these groups from a more 'algebraic' (i.e. as algebraic groups/group schemes as opposed to Lie groups) viewpoint? Is it even necessary to make such a distinction between the reps of the group scheme and the representations of its group values on certain $\mathbb{Q}$-algebras?

A: $\newcommand \G{\mathbf{G}}$ $\newcommand \GL{\mathrm{GL}}$ $\newcommand \SL{\mathrm{SL}}$ $\newcommand \Z{\mathbb{Z}}$ $\newcommand \Q{\mathbb{Q}}$ Just to get this out of the unanswered queue, let me give the following answer:
1) Yes! There are actually tons. Any book on 'linear algebraic groups' will cover what you want (although Waterhouse's book is strange it sidesteps a lot of the theory). Specifically though, I would recommend these notes of Milne--I think they are about as good as one could possibly hope for in terms of completeness. They have the downside of being somewhat cagey about using modern algebraic geometry, but only in language. Namely, Milne does talk about nilpotents (which are pivotal in the characteristic $p$ theory since such simple maps like $\text{SL}_p\to\text{PGL}_p$ have non-reduced kernel) but he insists of talking about $\text{MaxSpec}(A)$ instead of $\text{Spec}(A)$ for some unbeknownst reason--it doesn't make a difference, but it's worth noting.
I am also always eager to rep Brian Conrad's notes (for most things). Specifically, there are these from a first course on linear algebraic groups. They have the strong plusses of being written from a 'modern algebro-geometric viewpoint' (e.g. quotients are defined as quotient fppf sheaves, which is what they should be defined as), but falls prey to the neuroticism that befalls all live-TeXed notes--they're fairly all over the place. Unfortunately, that doesn't really cover what you're asking for because it doesn't cover the structure theory of reductive groups (and their representations). For that you'll have to look at notes from his follow-up course. Again, these are probably my favorite notes for the topic, but are somewhat hard to quickly look things up in (something Milne's notes excel in).
Finally, if you want a 'quick fix' you can look at the first (~50 page) section of these notes of Brian Conrad--I think the same material is roughly contained in the appendix to his book (with Prasad and Gabber) Pseudo-reductive Groups.
Let me just note that if you're really only interested in the groups you've mentioned (over $\mathbb{Q}$), then everything is easily describable.
For $\mathbf{G}_m$ (everything in here will be over $\mathbb{Q}$) representations $\mathbf{G}_m\to\GL(V)$ correspond to $\Z$-gradings $\displaystyle V=\bigoplus_{i\in\Z}V_i$ where $\G_m$ acts on $V_i$ by the character $z\mapsto z^i$. In particular, every representation is semisimple and the simple representations are just characters (which are precisely the maps $z\mapsto z^i$).
For $\SL_2$ things are ever so slightly more complicated. Namely, $\SL_2$ is reductive (in fact, semisimple) and thus every algebraic representation of $\SL_2$ is semisimple. Thus, we really only need to describe the simple representations of $\SL_2$. To do this, note that $\SL_2$ naturally acts on homogenous polynomials of degree $m$ in the variables $x,y$ (by $(a_{ij})f(x,y):=f(a_{11}x+a_{12}y,a_{21}x+a_{22}y)$, call this representation $V_m$. Then, every simple representation of $\SL_2$ is isomorphic to precisely one of these $V_m$.
(Note that it's not a coincidence that $V_m\cong \mathcal{O}(m)(\mathbb{P}^1)$ since $\mathbb{P}^1$ is the flag variety $\SL_2/B_2$ associated to $\SL_2$ and the Borel-Weil theorem describes a precise relation between representations of $\SL_2$ and (certain) line bundles on the flag variety--this works more genenerally for a semisimple group).
Finally, $\GL_2$ is also reductive (but not semisimple), thus to describe its representation theory we need only describe its simple representations. These come in two flavors. Namely, there is the irreducible tautological representation of $\GL_n$ (acting on $k^n$ in the usual way) and there are the representations $\wedge^i(k^n)$ for $i\leqslant n$. That's all of them.
Of course, to see where these came from--the real answer is the theory of dominant weights. That said, it's always easier to think about the analogy you know from the representation theory of a finite group. Namely, if $G$ is a finite group and $\text{Reg}(G)$ denotes the left regular representation of $G$, in other words $G$ acting on the group algebra $\mathbb{C}[G]$, then there is a decomposition
$$\text{Reg}(G)\cong\bigoplus_{\rho\in\text{Irr}(G)}\rho^{\dim\rho}$$
where $\text{Irr}(G)$ is the set of isomorphism classes of irreducible algebraic representations of $G$. A similar thing happens for a reductive group $G$. For example, for $\GL_n$ one has that the coordinate ring of $\GL_n$ (as a variety) decomposes as a $\GL_n\times\GL_n$-rep (via the multiplication map) as a direct sum of $V\boxtimes V^\ast$ where $V$ runs over the irreducible representations of $\GL_n$. So, see if you can use this to sort out what happens at least for $\G_m$.
2) As I mentioned in the comment, this really depends on what $\Q$-algebras you pick. For example, you know from the Yoneda philosophy that any representation $\rho:G\to\GL_n$ of an algebraic group $G$ is determined by the group maps $G(R)\to\GL_n(R)$ as $R$ varies over all $\Q$-algebras. In, fact it suffices to think about it for $R=\mathcal{O}_G(G)$ which gives you the notion of a comodule.
Of course, things are going to be bad if you want to consider just the values of the representation on some random $R$, even for examples $R=\Q$ I think. I don't have an example off-hand to be honest (there's probably not a hard one) but if you look anything other than $\Q$, say $\Q(i)$, you'll get lots of representations of $\GL_2(\Q(i))$ (say) that won't be algebraic--think about the one that is induced from the non-trivial automorphism of $\Q(i)$.


text:
Q: About Central limit theorem We prove Central limit theorem with characteristic function. If we know the $X_i$ are independent but not identically distributed, is there any weaker condition which still yields the convergence to normal distribution?

A: For example, suppose $X_i$ are independent with $\mathbb E(X_i) = 0$, $\text{Var}(X_i) = \sigma_i^2$, and $$\lim_{n \to \infty} \frac{1}{\sigma(n)^3} \sum_{i=1}^n \mathbb E[|X_i|^3] = 0$$
where $$\sigma(n)^2 = \text{Var}\left(\sum_{i=1}^n X_i\right) = \sum_{i=1}^n \sigma_i^2$$  Then $\displaystyle \frac{1}{\sigma(n)} \sum_{i=1}^n X_i$ converges in distribution to a standard normal random variable.

A: Following Robert Israel's notation elsewhere in this thread, we set $0 = \mathbb{E}(X_i) = 0$, $\sigma_i^2 = \text{Var}(X_i)$, and $\sigma(n)^2 = \sum_{i=1}^n \sigma_i^2$.
Lindberg's Condition: For every $\epsilon > 0$,
$\lim_{n\to\infty} \frac{1}{\sigma(n)^2} \sum_{i=1}^n \mathbb{E}\left(X_i^2 1_{\{ |X_i| \ge \epsilon \sigma(n)\}}\right) \to 0$.
Lyapunov's condition: There exists $\delta > 0$ such that $\lim_{n\to \infty}\frac{1}{\sigma(n)^{2 + \delta}} \sum_{i=1}^n \mathbb{E} \left( |X_i|^{2 + \delta}\right) \to 0$.
The Lyapunov condition implies the Lindberg condition, and the Lindberg condition implies the conclusion of the central limit theorem, ie. that $\frac{\sum_{i=1}^n X_i}{\sigma(n)} \Rightarrow N(0,1)$, where $N(0,1)$ is the standard normal. (Robert Israel's answer presents the Lyapunov condition with $\delta = 1$).


text:
Q: Best way to downcast to right template from abstract class I recently had a C++ assignment, where I was confronted to a problem about polymorphism.
We needed to store values in a templated class, which was inheriting from an abstract interface class.
enum eOperandType {
    Int8,
    Int16,
    Int32,
    Float,
    Double
};

class IOperand {
public:
    virtual eOperandType getType() const = 0; // Type of the instance
    virtual IOperand const *operator+(IOperand const &rhs) const = 0;
    virtual ~IOperand() {}
};

template<typename T>
class Operand : public IOperand {
public:
    Operand(T const &n, eOperandType type);
    eOperandType getType() const;
    IOperand const *operator+(IOperand const &rhs) const;

    T const value;
    eOperandType const type;
};

For all the assignment, we were forbidden to edit the IOperand class, but free to use any class we need behind.
Later on the code execution, numbers are instanced and then stored in a container as IOperand*. We then get this list in order to manipulate numbers.
My problem was to find how to downcast the IOperand* into the right Operand type, in order to manipulate it and get it's value.
I tried multiples approaches for a week, looking into all templates behaviour (with hitting a wall when I tried to use Operand<op.getType()> with T being the enum)
My actual design is using a lot of switches:
switch (op.value->getType()) {
    case Int8:
        if (dynamic_cast<Operand<int8_t>*>(op.value.get())->value != dynamic_cast<Operand<int8_t>*>(stack.front().get())->value) {
            throw RuntimeError("Assert failed. Whoopsie");
        }
        break;
    case Int16:
        if (dynamic_cast<Operand<int16_t>*>(op.value.get())->value != dynamic_cast<Operand<int16_t>*>(stack.front().get())->value) {
            throw RuntimeError("Assert failed. Whoopsie");
        }
        break;
    case Int32:
        if (dynamic_cast<Operand<int32_t>*>(op.value.get())->value != dynamic_cast<Operand<int32_t>*>(stack.front().get())->value) {
            throw RuntimeError("Assert failed. Whoopsie");
        }
        break;
    case Float:
        if (dynamic_cast<Operand<float>*>(op.value.get())->value != dynamic_cast<Operand<float>*>(stack.front().get())->value) {
            throw RuntimeError("Assert failed. Whoopsie");
        }
        break;
    case Double:
        if (dynamic_cast<Operand<double>*>(op.value.get())->value != dynamic_cast<Operand<double>*>(stack.front().get())->value) {
            throw RuntimeError("Assert failed. Whoopsie");
        }
        break;
    default:
        throw RuntimeError("wut");
        break;
}

What would be the best clean solution to solve my problem? I need to "downcast" my value at multiples places and functions in order to manipulate the value, the assert code here is just an example among many others.
I can here use C++14, but not any external libs.

A:
hitting a wall when I tried to use Operand with T being
  the enum

Templates are evaluated at compile time. The compiler generates code for each type you have used. A dynamic value like op.getType() would require the compiler to create code after you have compiled, which is certainly possible in JIT compiled languages, but not in C++.
I'm afraid there is no 'pretty' solution to your problem. You really need a kind of switch statement as you've shown, and decide your cast based on the value of getType(). Depending on your use cases, virtual functions could help you, e.g. if you would like to know the byte size of T
virtual size_t getSizeOf()
{
    return sizeof(T);
}

but since you're not allowed to modify IOperand, you're stuck with your solution.


text:
Q: Multiple buttons for same function with if statement I've tried to make my own case function, but I cannot get it to "show stuff" once I've hidden them on first click. So my question is what am I doing wrong, how can I solve it, and how should I've done it instead?
My only requirement is that multiple buttons can use the same code to show/hide the same object – hence things like oddClick won't work since that'll require unnecessary clicks to get even/odd again (I think?).
        $('.boxbtn').on('click', function () {
        var boxwidth = $('.box').width();
        console.log(boxwidth);
        console.log('-'+boxwidth+'px');
        var state = 1;

        if(state == 0) {  // I think we are trying to compare value here.
/*              alert("foo"); */
            var state = 1;
            console.log(state);
            /*show stuff here*/
        }
        else {
/*              alert("bar"); */
            var state = 0;
            console.log(state);
            /*hide stuff here*/
        }

    });

A: this line 5: var state = 1; causes it to always go into "else
var state = 1; //placed on global scope
 $('.boxbtn').on('click', function () {
        var boxwidth = $('.box').width();
        console.log(boxwidth);
        console.log('-'+boxwidth+'px');
        //var state = 1; removed from function scope

        if(state == 0) {
/*              alert("foo"); */
            state = 1;
            console.log(state);
            /*show stuff here*/
        }
        else {
/*              alert("bar"); */
            state = 0;
            console.log(state);
            /*hide stuff here*/
        }

    });

Fiddle: http://jsfiddle.net/8ubk5c0f/

A: Declare state variable outside click function.
var state = 1; // Do not write inside click function scope

A: For detecting the state of your object, you should use the object properties (instead of a parallel state variable).
Using the value of boxwidth for instance.

A: In more simple way:

$('.boxbtn').on('click', function () {
    var boxwidth = $('.box').width(); //Not sure why you want this
    console.log(boxwidth);
    console.log('-'+boxwidth+'px');
    var btnVal=$(this).text(); //get the button text
    if(btnVal=="Show Stuff") //if it is show stuff
    {
        $(this).text('Hide Stuff'); //change its text
        alert('stuff shown');
        /*show stuff here*/ //do the functionality
    }
    else {
        $(this).text('Show Stuff'); //change back to normal
        alert('stuff hidden');
        /*hide stuff here*/ //hide functionality
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" class="boxbtn">Show Stuff</button>

A: var state = 0; //placed on global scope

$('.boxbtn').on('click', function () {
    var boxwidth = $('.box').width();
    console.log(boxwidth);
    console.log('-'+boxwidth+'px');

    if(state == 0) {
        state=1;
        console.log(state);
    }
    else {
        state = 0;
        console.log(state);
    }

});


text:
Q: Javascripting Scope Chain Practice I am doing the javascript practices from nodeschool.io, and I was given this code:

var a = 1, b = 2, c = 3;

(function firstFunction(){
 var b = 5, c = 6;

 (function secondFunction(){
  var b = 8;

  (function thirdFunction(){
   var a = 7, c = 9;

   (function fourthFunction(){
    var a = 1, c = 8;

   })();
  })();
 })();
})();

I am not able to access anything inside this so I attempted it like this:

var a = 1, b = 2, c = 3;

var start = (function firstFunction(){
 var b = 5, c = 6;

 var secondFunction = (function secondFunction(){
  var b = 8;

  (function thirdFunction(){
   var a = 7, c = 9;

   (function fourthFunction(){
    var a = 1, c = 8;

   })();
  })();

  return {
   secondFunction: secondFunction,
   printB: function () {
    return b;
   }
  }

 })();

 return {
  printC: function () {
   return c;
  }
 }

})();

console.log("a: " + a + ", b: " + start.secondFunction.printB() + ", c: " + start.printC());

I don't know if my approach is right but I've been stick on this all day. How would you approach this and why isn't my code working to get into secondFunction.printC?

A: Try something like this.
var a = 1, b = 2, c = 3;

var start = (function firstFunction(){
  var b = 5, c = 6;
  var obj = {};

  (function secondFunction(){
    var b = 8
    obj.secondFunction = function(){
        return b;
    };
    (function thirdFunction(){
        var a = 7, c = 9;
        obj.thirdFunction = function(){
            return c;
        };
        (function fourthFunction(){
            var a = 1, c = 8;
            obj.fourthFunction = function(){
                return c;
            };
        })();
    })();
  })();
  return obj
})();

console.log ( start.secondFunction() )