Skip to content

Instantly share code, notes, and snippets.

View sivabudh's full-sized avatar

Sivabudh Umpudh sivabudh

View GitHub Profile
__author__ = 'Pac'
import collections
Card = collections.namedtuple('Card', ['rank', 'suit'])
class FrenchDeck:
ranks = [str(n) for n in range(2, 11)] + list('JQKA')
suits = 'spades diamonds clubs hearts'.split()
@sivabudh
sivabudh / reverse_list.c
Created February 14, 2014 07:48
The French Solution
#include <stdio.h>
typedef struct node
{
int data;
struct node *next;
};
struct node* reverse(struct node* head)
@sivabudh
sivabudh / sample
Last active August 29, 2015 13:56
class Object2 {
int y, x, z;
Object2 () { // constructor
y = 5; x = 2; z = 1;
}
public int doAnother() {
y += 1;
return y;
}
class MyRobo {
int x = 5;
static int y = 6;
}
class Untitled {
public static void main(String[] args) {
MyRobo robo1 = new MyRobo();
MyRobo robo2 = new MyRobo();
robo1.x += 1;
@sivabudh
sivabudh / TriangleArea
Created March 5, 2014 12:22
How to calculate triangle area from command line inputs
import java.util.Scanner;
class TriangleArea {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.println("This program will help you calculate the area of a triangle.");
System.out.print("What's the height of the triangle? ");
@sivabudh
sivabudh / gist:9366609
Created March 5, 2014 12:53
How to use for loop.
import java.util.*;
class Untitled {
public static void main(String[] args) {
String string = "5,6,7,8";
String[] strings = string.split(","); // this array has 4 numbers
// "for loop" first example
for(String str : strings) // for loop difference
@sivabudh
sivabudh / Untitled
Created March 21, 2014 07:59
The difference between static and non-static
class Untitled {
public static void main(String[] args) {
// Static method
add2(1, 4);
// Non-static method
Untitled object = new Untitled();
object.add1(1, 4);
}
public double add1(int x, int y)
class Untitled {
public static void main(String[] args) {
int [] array = {1,5,2,-1};
// sort
for(int k = 0; k<array.length; k++){
for(int i = k; i<array.length; i++){
if(array[i]<array[k]){
int temp = array[k];
class Untitled {
public static void main(String[] args) {
int [][] k ={
{1,2}, // first element of k
{3,4,5}, // second element of k
{8,10,12,14} // third element of k
};
System.out.println(k.length);
System.out.println(k[0].length);
System.out.println(k[1].length);
public class Untitled {
// int is called "return value"
// someFunction is called "method"
// return is the Java keyword which returns result
int someFunction(int n) {
if(n==0)
return 0;
else
return someFunction(n-1) + n;
}