@.         
                @@         
          :     :@         
          .@     @         
           :@    @+        
            +@   @@        
        `@@@;'@` +@        
       '@@'+@@@@; @        
               @@@@'       
                +@@@.      
                 `@@@+     
       :@@:@.     :@@@     
        .@@@@:     @       
          @#@@@    @:      
          .@ '@@@  @@      
           ;@  #@@@`.      
            @+  @@@@@      
             @   +@@@@:    
        @@@@@@.    +@@@+   
        @@.@@@        .    
         @,                
         `@                
          +@               
        #@@;               
       :@:@@@              
       .@ #+#@             
       `@  @ @+            
        @'  @ @            
        :@  :@@            
         @@  #;            
          @:               
           @:              
                .          
                @+         
        ;:      `@         
       +@@@      ::        
        #@@@'     @        
         :@@@@    :;       
          `@@@@:   @       
           .@@@@#  @`      
             @;@@@`+@      
              @ @@@@@      
               @ '@@#      
                @  ;       
                 @         
         @@@:    :@        
        @@@@@@:   ##       
        +  :@@@@.  @`      
         @   :@@@@ ;@      
         +@    ;@@@@@      
          @#     #@@@      
           @       +.      
        @@@@@              
       @@@@@@+             
       @   ;@@             
       #,   ;@+            
        @`   @@            
        :@# @+@            
         .@@@:`            
                           
           :               
         . #;              
        @@@@@              
       @.`#@@@             
       @    @@.            
       :#    @@            
        @#   @@            
         @@@@##            
          @@@              
                           
                           
                           
       .@@@@@#`            
       @+:;;@@@@:          
       ;@ @ @@ @@@`        
        @@@@ @@` @@#       
         ;@@  :@; :@@`     
          @+    @@  @@+    
          #@     `@+ .@#   
           @:      .@#:@;  
            @         :@   
                     
 
 

Popular Posts

Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts
Sublime Text Compile/ Build and Run Codes

I recently started with Sublime Text Editor, it's an amazing text editor with elegance and beauty. This editor has some of the most advanced features I have seen so far. For people who are using notepad++ this is a good alternative to choose from.

When I started I was little confused as to how to compile and Run codes with this editor.Here is a walk through.

Compiling/ Building  

I shall take java as an example rest languages can be configured similarly

  • First open a new File and save it with a proper name say "Test.java"
  • Open command Prompt and type javac to check if the java compiler path is correctly set.Type java at cmd and check if the command is recognizable.If any error comes set the Path environment variable for Java first.
  • Then Goto Tools>Build System and check the Automatic or JavaC option.
  • Then Press ctrl+B to build the console will display Finished in [time ] message.
  • Now to Run you can either goto the directory containing the compiles file and open cmd there and type 
  • "java Test" to run or proceed to next step and learn how to setup a Build system to Run from sublime text.

Running The Compiled File / Making the New Build System


  • Sublime uses its build-system files of corresponding languages to build the source code.So we can either make a new build system or edit the already exiting one.
  • To make a new build system goto Tools>Build System>New Build System. Then Type the new Build System commands.
  • But as I am using java here for which sublime text already has the build system, I prefer editing the current one , usually the file is located at 
  • C:\Users\{username}\AppData\Roaming\Sublime Text 2\Packages\Java\JavaC.sublime-build
  • Open the file JavaC.sublime-build in sublime text and them add the below code snippet

{
"cmd": ["javac", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
"variants": [

        { "cmd": ["javac", "-Xlint", "$file"],
          "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
          "selector": "source.java",
          "name": "Java Lintter"
        },  

        { "cmd": ["java", "$file_base_name"],
          "name": "Run Java"
        }
    ]

}

Over here we are just adding two variant to the build system the default being the first one. The Last one with the name "Run Java" is the one that is gonna Run the compiled file. So that it Runs it is necessary that the file name and the class name in the source name with the main (taking about java here) should be same or else it wont find the file.

Save the file and then now to compile the code you need to press ctrl+b  but to Run you just need to type ctrl+shift+p and then there type "Run java". That's it. The output will be displayed in the sublime text console.

Continue Reading

Graph are one of the most interesting topic to be discussed, but many who begin get confused as to how to implement it. There are many way to implement a graph here is one of the simplest implementation. Where the no. of vertex and the info about the edge is taken as an input.
#include<iostream>
#include<string>
#include<vector>
using namespace std;
struct Edge
{
 int destination;
 int weight;
};
void printGraph(vector< vector<Edge> > v){
 for(int i=0;i<v.size(); i++){
// same thing can also be done using iterator;
  cout<<i<<": ";
  for(int j=0;j<v[i].size();j++)
   cout<<v[i][j].destination<<" ";
 }
}
Edge getEdge(int dest, int weight=0){
 Edge e;
 e.destination = dest;
 e.weight = weight;
 return e;
}
int main(){
 vector< vector<Edge> > g;

        // destination of each vertex here max is choosen as 20;
 int dest[20];

 int n;//number of vertex;
 cout<<"Enter the no of vertex\n";
 cin>>n;
 for(int i=0;i<n;i++){
  cin.sync();
  cout<<"Enter no of edges";
  int ne;
  cin>>ne;
  cout<<"Enter all the destination";
  for(int j=0;j<ne;j++)
   cin>>dest[j]; 

// enter all  destination in one line here 1 2 3 4 etc.
  vector<Edge> temp;
  for(int j=0;j<ne;j++){

                        // weight is kept at zero, can be passed here.
   Edge e = getEdge(dest[j]);
   temp.push_back(e);

  }
  g.push_back(temp);
  temp.clear();
 }
 printGraph(g);
 return 0;

}
The graph in the above is directed graph so if an undirected graph is made one should keep in mind about adding the symmetric edge too. Here The weight is given a default value of zero if one wants to assign weight to different edge , with the destination also pass the weight of the edge. This is an implementation using vector, map or list can also be used according too the need.
Continue Reading

Taking inputs, yes you must be knowing them already but here is a little hack that i really liked. Usually in competitive coding the input format is predefined and then there are time when you have to take input of multiple value in the same line for example.

1 2 3 4 5 6 6 7 9

if this is to be stored in an array of type int but the user enters all the values in single line then this can be done.
if we want to enter 10 number in the array, then :

int x[10];
for(int i=0;i<10;i++)
     cin>>x[i];

Now when prompted for input enter all the values in one line, thats it. 
a second solution is using the istringstream, if you already have a string like "1 2 3" then this can be done.

int n;
string s="1 2 3 4 5 6 7 8 9";
int a[9];
int i=0;
istringstream st(s);
while(st>>n){
a[i]=n;
i++;
}
// and a will have iall the element in specified position.
Continue Reading
Windows 8  Ad Hoc Using Command Prompt With Batch File

Windows 8 Does not allow to make Ad Hoc network , And the new update to it windows 8.1 doesn't even allow to connect to and Ad-Hoc network. The reasons are still not clear, but even this is not completely true. Windows 8 just removed the front end GUI to make the Ad-Hoc. Using CMD that can be done. The netsh command does this trick well,The command is something like this:

netsh wlan set hostednetwork mode=allow ssid=<network name> key=<password 8 char>
netsh wlan start hostednetwork

Here is a picture showing how to check if Hoatstednetwork is supported or not.

But typing these lines is painful and yes most of are lazy. So I thought of Making a batch file that Will some what automate this feature with little bit of user intraction in with the user can choose the Network name and password. Below goes the code for the Batch file that Present with a Menu that can Start, Stop the ad-hoc.
Ps: The Network created wont be visible on you laptop but other friends can see it and connect, If in the first attempt the network is not visible try first stoping the Ad-Hoc by Pressing 2 the second option in the Menu.


Copy the below code to a text file and save it as "adhoc.bat" remember to run it as Administrator 

Continue Reading
Understanding the 'this' keyword in Javascript .


Understanding this took me quite some time and the way I learn is by reading source code and then interpreting what I get from them.I write so that I don't forget it later on. This Post I will try to explain how the awesome keyword 'this' works in javascript as it has different meaning at different places.
Before starting I would like you to remember the key rule :
'this' always refers to the owner.
So,here are instances that Prove the above line.This is different is different circumstance.

Below are different situations in which this can be used ..

Continue Reading
Django 'Unresolved import' Error of Pydev in Ubuntu Fix

Recently I switched from Windows to Ubuntu and being a beginner I had to face a few problems setting up everything . For writing Django apps I use Aptana IDE that in turn uses the Pydev plugin. I downloaded the tar ball from aptana official site .Installed Django using the terminal. Extracted Aptana tar ball in home directory and Ran it by double clicking on 'AptanaStudio3'. Everything looked nice until I imported a django app in the workspace . All the Djano import when marked as error and they could not be resolved . There was nothing wrong with the Python path variable and when running the Project from the terminal everything worked .The Problem was with Aptana/Eclipse that it could not resolve the path. I found the reason after some time and this is how i solved it .

The problem:


Continue Reading
AS EXPLAINED TO A 4 YEAR OLD CHILD, SOME QUESTIONS THAT YOU THOUGHT WERE TOUGH


Q1.How should I explain dynamic programming to a 4-year-old?

*writes down "1+1+1+1+1+1+1+1 =" on a sheet of paper*
"What's that equal to?"
*counting* "Eight!"
*writes down another "1+" on the left*
"What about that?"
*quickly* "Nine!"
"How'd you know it was nine so fast?"
"You just added one more"
"So you didn't need to recount because you remembered there were eight! Dynamic Programming is just a fancy way to say 'remembering stuff to save time later'"


Continue Reading

Prime no are one of the most mysterious no. in the Number theory . There are a lot on method of checking if a no is Prime or not, two most famous are the Probabilistic and Naive method . Naive method is simple and efficient this.
Before know the better let's discuss what not to do, here is the python code for checking Prime that is less efficient.

def is_prime(num):
    c=0
    for i in range(2,num):
        if num % i==0:
            c+=1
        if c==0:
            return True
        else:
            return False


here the loop iterates till the given number, which is useless.
This can be optimized by running the first loop untill the square root of the number abd checking for the factors. This works because any composite number can be factorized and written into product of number in which one number is less than the square root of the number.
HERE is the better optimized NAIVE Method for checking primes 


def NaivePrime(n):
    check=True
    for i in range(2,int(n**0.5)+1):
        if i%2==0 and i !=2:
            continue
        else:
            if n%i==0:
                check=False
                print "%d is factor" % i 
                break
    return check

this runs much fast and in the conventional way if very large numbers are tested then an overflow can be encountered .
And then comes the Sieve of Eratosthenes which is much faster than previous methods given.Its modification the Sieve of Atkins is even more efficient. If space complexity is also to be taken into account then a segmented Sieve is the best method.
This is the code for Sieve of Eratosthenes

def p(n):
  is_p=[False]*2 + [True]*(n-1)
  for i in range(2, int(n**0.5)):
    if is_p[i]:
        for j in range(i*i, n, i):
            is_p[j] = False
  for i in range(2, n):
    if is_p[i]:
      yield i

print list(p(102))



Continue Reading

Recently I was asked by my friend to write a simple code to check if two strings are anagram or not.I wrote three different approach to it in python.I was not allowed to change the input format so i had to do some extra work and write a function to get input.
Here is the question that was given:

Anagram

--------------------------
In this problem, you are given two strings S1 and S2, your task is to determine whether one string is an anagram of the other. An anagram of a string is a string obtained by permuting the letters of a string. For example aaba and aaab are anagrams, while abcd and deba are not.
Continue Reading


Before moving on with this I would before you can actually do that in one click you have to take a little bit of pain to set up the system, I promise it’s a one time setup and won’t poke you ever after ,just a click and that
Ugly addition to the title and filename removed in a click. So far if you are not getting as to what i am upto ; in plane and simple words: many time you must have downloaded songs that has this ugly thing like “songname_www.xyz.com” now what it will do is that it will just remove that www.xyz.com  stuff from the title and filename in a click. Just follow the steps

Continue Reading