├── Java ├── FactorialExample.java ├── javaarraylenth ├── MultiplicationTable.java ├── StarTriangle.java ├── Pattern.java ├── Alphabet.java ├── Power.java ├── Fibonacci.java ├── HelloWorld.java ├── Temp.java ├── InsertionSort.java ├── LeapYear.java ├── TOH.java ├── SortArray.java ├── SelectionSort.java ├── Vector.java ├── Calculator.java ├── LinkedList.java ├── HeapSortAlgo.java ├── priority_queue.java └── Btree.java ├── Python ├── pythonarraylength ├── Hello World.py ├── Acii.py ├── AreaOfCircle.py ├── 1first.py ├── numberpattern.py ├── CamelCaseWordCounter.py ├── ASCII Finder.py ├── divisibleBy5.py ├── Amstrong_num.py ├── practi2.py ├── datetime.py ├── quadratic.py ├── Factorial.py ├── Star Pattern.py ├── Caesar_cipher.py ├── Prime_Numb.py ├── AstrologerStarPattern.py ├── magic.py ├── dfs_graph.py ├── Calculator.py ├── Hangman.py ├── Linear Regression.py └── currency.py ├── fortran └── HelloWorld.f95 ├── Rust ├── HelloWorld.rs └── loop.rs ├── R ├── helloWorld.R ├── hcf.R └── random.R ├── HTML ├── .HelloWorld.kate-swp ├── HelloWorld ├── SignIn.html └── htmldev.html ├── Go ├── hello_world.go ├── pythagoras.go ├── prime_check.go ├── calculator.go └── huffman.go ├── php ├── helloWorld.php └── signup.php ├── Scala ├── Hello World.scala ├── List.scala ├── String Interpolation.scala └── Queue.scala ├── C++ ├── HelloWorld ├── LCSRecursive.cpp ├── ceaser.cpp ├── Operator_Overloading └── fcfs.cpp ├── Perl └── helloworld.pl ├── C ├── Hello World.c ├── HelloHactomber.c ├── StarPattern │ └── star.c ├── ReverseNum.c ├── Factorial.c ├── Length Converter.c ├── AddInt.c ├── LCM.c ├── Multiply two numbers.c ├── pascalpyramid.c ├── palindrome.c ├── VowelCons.c ├── PerfectSquare.c ├── Vowel finder.c ├── ConcatString.c ├── Switch_Cal.c ├── calculator_C.c ├── SparseMatrix.c ├── QueueExample.c ├── ReverseStr.c ├── Round Robin.c ├── First Come First Serve.c └── curency.c ├── README.md ├── C# ├── Hello World.cs ├── Star Pattern.cs ├── Reverse.cs ├── Fibonacci.cs ├── Decimal_Binary.cs ├── palindrome.cs └── Calculator.cs └── javascript └── helloworld.html /Java/FactorialExample.java: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Python/pythonarraylength: -------------------------------------------------------------------------------- 1 | cars = ["Ford", "Volvo", "BMW"] 2 | x = len(cars) 3 | print(x) 4 | -------------------------------------------------------------------------------- /Python/Hello World.py: -------------------------------------------------------------------------------- 1 | print("Hello sri lanka!") 2 | print('Hello World, A new coder is born') 3 | -------------------------------------------------------------------------------- /fortran/HelloWorld.f95: -------------------------------------------------------------------------------- 1 | program hello 2 | Print *, "Hello World!...4...." 3 | end program Hello -------------------------------------------------------------------------------- /Python/Acii.py: -------------------------------------------------------------------------------- 1 | c = input("Enter a character: ") 2 | 3 | print("The ASCII value of '" + c + "' is",ord(c)) -------------------------------------------------------------------------------- /Rust/HelloWorld.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Hello World! This is HacktomberFest Season.. "); 3 | } 4 | -------------------------------------------------------------------------------- /R/helloWorld.R: -------------------------------------------------------------------------------- 1 | # My first program in R Programming 2 | myString <- "Hello, HacktomberFest!" 3 | 4 | print ( myString) 5 | -------------------------------------------------------------------------------- /HTML/.HelloWorld.kate-swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Supuna-Kaumada/HacktomberfestHelloWorld/HEAD/HTML/.HelloWorld.kate-swp -------------------------------------------------------------------------------- /Java/javaarraylenth: -------------------------------------------------------------------------------- 1 | String[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; 2 | cars[0] = "Opel"; 3 | System.out.println(cars[0]); 4 | -------------------------------------------------------------------------------- /Go/hello_world.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | func main() { 5 | 6 | fmt.Println("!... Hello World ...!") 7 | } 8 | -------------------------------------------------------------------------------- /php/helloWorld.php: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /Python/AreaOfCircle.py: -------------------------------------------------------------------------------- 1 | 2 | def findArea(r): 3 | PI = 3.142 4 | return PI * (r*r); 5 | 6 | print("Area is %.6f" % findArea(5)); 7 | 8 | -------------------------------------------------------------------------------- /Scala/Hello World.scala: -------------------------------------------------------------------------------- 1 | object HelloWorld { 2 | def main(args: Array[String]): Unit = { 3 | println("Hello, world!") 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /C++/HelloWorld: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | cout << "Hacktomberfest" << endl; 6 | return 0 7 | } 8 | -------------------------------------------------------------------------------- /Perl/helloworld.pl: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/perl 3 | 4 | # Modules used 5 | use strict; 6 | use warnings; 7 | 8 | # Print function 9 | print("Hello World\n"); -------------------------------------------------------------------------------- /C/Hello World.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | printf("Hello World!"); 5 | printf("Hello UWU!"); 6 | printf("Bonjor UWU!"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /C/HelloHactomber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | /* Our first simple C basic program */ 5 | printf("Hello HactomberFest! "); 6 | getch(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Python/1first.py: -------------------------------------------------------------------------------- 1 | a=int(input("enter number 1;")) 2 | b=int(input("enter number 2;")) 3 | if(a==b): 4 | print("both are equal") 5 | elif a>b: 6 | print(a,"is larger") 7 | else: 8 | print(b,"is larger") 9 | -------------------------------------------------------------------------------- /Python/numberpattern.py: -------------------------------------------------------------------------------- 1 | rows = 6 2 | for num in range(rows): 3 | for i in range(num): 4 | print(num, end=" ") # print number 5 | # line after each row to display pattern correctly 6 | print(" ") 7 | -------------------------------------------------------------------------------- /Python/CamelCaseWordCounter.py: -------------------------------------------------------------------------------- 1 | import math 2 | import os 3 | import random 4 | import re 5 | import sys 6 | 7 | x=input() 8 | s=1 9 | for i in x: 10 | if i.isupper(): 11 | s+=1 12 | print(s) 13 | -------------------------------------------------------------------------------- /HTML/HelloWorld: -------------------------------------------------------------------------------- 1 | 2 | 3 | First WebPage 4 | 5 | 6 | 7 | 8 |

Hello World

9 | 10 | 11 | -------------------------------------------------------------------------------- /Python/ASCII Finder.py: -------------------------------------------------------------------------------- 1 | # Program to find the ASCII value of the given character 2 | 3 | # Change this value for a different result 4 | c = 'w' 5 | 6 | # Uncomment to take character from user 7 | #c = input("Enter a character: ") 8 | 9 | print("The ASCII value of '" + c + "' is",ord(c)) -------------------------------------------------------------------------------- /Python/divisibleBy5.py: -------------------------------------------------------------------------------- 1 | def findDivisible(numberList): 2 | for num in numberList: 3 | if (num % 5 == 0): 4 | print(num) 5 | 6 | numList = input(int(i) for i in input("Enter number list").split("")) 7 | print("Finding divisible of 5 in a list") 8 | findDivisible(numList) 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HacktomberfestHelloWorld 2 | 3 | Feel Free to send me Pull requests :-) 4 | 5 | If you need any more languages, Feel free to create a folder in the name of that language and continue. 6 | Don't directly put files in the root directory. 7 | 8 | ## Don't Forget to Star the Original Repo ;-) 9 | -------------------------------------------------------------------------------- /Scala/List.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.immutable._ 2 | object MainObject{ 3 | def main(args:Array[String]){ 4 | var list = List(1,8,5,6,9,58,23,15,4) 5 | var list2:List[Int] = List(1,8,5,6,9,58,23,15,4) 6 | println(list) 7 | println(list2) 8 | } 9 | } -------------------------------------------------------------------------------- /Java/MultiplicationTable.java: -------------------------------------------------------------------------------- 1 | public class MultiplicationTable { 2 | 3 | public static void main(String[] args) { 4 | 5 | int num = 9, i = 1; 6 | while(i <= 10) 7 | { 8 | System.out.printf("%d * %d = %d \n", num, i, num * i); 9 | i++; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Java/StarTriangle.java: -------------------------------------------------------------------------------- 1 | class StarTriangle 2 | { 3 | public static void main(String[] args) 4 | { 5 | int i,j,k; 6 | for(i=1; i<=5; i++) 7 | { 8 | for(j=4; j>=i; j--) 9 | { 10 | System.out.print(" "); 11 | } 12 | for(k=1; k<=(2*i-1); k++) 13 | { 14 | System.out.print("*"); 15 | } 16 | System.out.println(""); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Rust/loop.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | 'outer: loop { 3 | println!("Outer loop"); 4 | 5 | 'inner: loop { 6 | println!("Inner loop"); 7 | 8 | // This breaks the outer loop 9 | break 'outer; 10 | } 11 | } 12 | 13 | println!("Exited Outer loop"); 14 | } -------------------------------------------------------------------------------- /Scala/String Interpolation.scala: -------------------------------------------------------------------------------- 1 | class StringExample{ 2 | var pi = 3.14 3 | def show(){ 4 | println(s"value of pi = $pi") 5 | } 6 | } 7 | 8 | object MainObject{ 9 | def main(args:Array[String]){ 10 | var s = new StringExample() 11 | s.show() 12 | } 13 | } -------------------------------------------------------------------------------- /Python/Amstrong_num.py: -------------------------------------------------------------------------------- 1 | num = 15468 2 | 3 | order = len(str(num)) 4 | sum = 0 5 | 6 | temp = num 7 | while temp > 0: 8 | digit = temp % 10 9 | sum += digit ** order 10 | temp //= 10 11 | 12 | #result 13 | if num == sum: 14 | print(num," is an Armstrong number") 15 | else: 16 | print(num," is not an Armstrong number") -------------------------------------------------------------------------------- /Java/Pattern.java: -------------------------------------------------------------------------------- 1 | public class Pattern { 2 | public static void main(String[] args) { 3 | int rows = 5; 4 | for(int i = 1; i <= rows; ++i) { 5 | for(int j = 1; j <= i; ++j) { 6 | System.out.print("* "); 7 | } 8 | System.out.println(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Python/practi2.py: -------------------------------------------------------------------------------- 1 | x=int(input("EnterSubject Mark 1;")) 2 | y=int(input("EnterSubject Mark 2;")) 3 | z=int(input("EnterSubject Mark 3;")) 4 | a=x+y+z 5 | b=a/3 6 | if(b>80): 7 | print("your grade is A") 8 | elif(b>60): 9 | print("your grade is B") 10 | elif(b>40): 11 | print("your grade is c") 12 | else: 13 | print("your are fail") 14 | -------------------------------------------------------------------------------- /Python/datetime.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | now = datetime.now() 4 | 5 | mm = str(now.month) 6 | 7 | dd = str(now.day) 8 | 9 | yyyy = str(now.year) 10 | 11 | hour = str(now.hour) 12 | 13 | mi = str(now.minute) 14 | 15 | ss = str(now.second) 16 | 17 | print mm + "/" + dd + "/" + yyyy + " " + hour + ":" + mi + ":" + ss 18 | 19 | 20 | -------------------------------------------------------------------------------- /C/StarPattern/star.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i, j, rows; 5 | 6 | printf("Enter number of rows: "); 7 | scanf("%d",&rows); 8 | 9 | for(i=1; i<=rows; ++i) 10 | { 11 | for(j=1; j<=i; ++j) 12 | { 13 | printf("* "); 14 | } 15 | printf("\n"); 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Java/Alphabet.java: -------------------------------------------------------------------------------- 1 | public class Alphabet { 2 | public static void main(String[] args) { 3 | char c = '*'; 4 | if( (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 5 | System.out.println(c + " is an alphabet charackter."); 6 | else 7 | System.out.println(c + " is not an alphabet."); 8 | } 9 | } -------------------------------------------------------------------------------- /C#/Hello World.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace HelloWorld 3 | { 4 | class Hello 5 | { 6 | static void Main() 7 | { 8 | Console.WriteLine("Hello World!"); 9 | 10 | // Keep the console window open in debug mode. 11 | Console.WriteLine("Press any key to exit."); 12 | Console.ReadKey(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Java/Power.java: -------------------------------------------------------------------------------- 1 | public class Power { 2 | public static void main(String[] args) { 3 | int base = 3, exponent = 4; 4 | long result = 1; 5 | while (exponent != 0) 6 | { 7 | result *= base; 8 | --exponent; 9 | } 10 | System.out.println("Answer = " + result); 11 | } 12 | } -------------------------------------------------------------------------------- /R/hcf.R: -------------------------------------------------------------------------------- 1 | hcf <- function(x, y) { 2 | if(x > y) { 3 | smaller = y 4 | } else { 5 | smaller = x 6 | } 7 | for(i in 1:smaller) { 8 | if((x %% i == 0) && (y %% i == 0)) { 9 | hcf = i 10 | } 11 | } 12 | return(hcf) 13 | } 14 | 15 | num1 = as.integer(readline(prompt = "Enter first number: ")) 16 | num2 = as.integer(readline(prompt = "Enter second number: ")) 17 | print(paste("The H.C.F. of", num1,"and", num2,"is", hcf(num1, num2))) -------------------------------------------------------------------------------- /C/ReverseNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n, reversedNumber = 0, remainder; 5 | 6 | printf("Enter an integer: "); 7 | scanf("%d", &n); 8 | 9 | while(n != 0) 10 | { 11 | remainder = n%10; 12 | reversedNumber = reversedNumber*10 + remainder; 13 | n /= 10; 14 | } 15 | 16 | printf("Reversed Number = %d", reversedNumber); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Java/Fibonacci.java: -------------------------------------------------------------------------------- 1 | public class Fibonacci { 2 | 3 | public static void main(String[] args) { 4 | 5 | int n = 10, t1 = 0, t2 = 1; 6 | System.out.print("First " + n + " terms: "); 7 | 8 | for (int i = 1; i <= n; ++i) 9 | { 10 | System.out.print(t1 + " + "); 11 | 12 | int sum = t1 + t2; 13 | t1 = t2; 14 | t2 = sum; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Go/pythagoras.go: -------------------------------------------------------------------------------- 1 | package pythagoras 2 | 3 | import ( 4 | "math" 5 | ) 6 | 7 | //Vector defines a tuple with 3 values in 3d-space 8 | type Vector struct { 9 | x float64 10 | y float64 11 | z float64 12 | } 13 | 14 | //Distance calculates the distance between to vectors with the Pythagoras theorem 15 | func Distance(a, b Vector) float64 { 16 | res := math.Pow(b.x-a.x, 2.0) + math.Pow(b.y-a.y, 2.0) + math.Pow(b.z-a.z, 2.0) 17 | return math.Sqrt(res) 18 | } 19 | -------------------------------------------------------------------------------- /Python/quadratic.py: -------------------------------------------------------------------------------- 1 | import cmath 2 | 3 | a = 1 4 | b = 5 5 | c = 6 6 | 7 | # To take coefficient input from the users 8 | # a = float(input('Enter a: ')) 9 | # b = float(input('Enter b: ')) 10 | # c = float(input('Enter c: ')) 11 | 12 | # calculate the discriminant 13 | d = (b**2) - (4*a*c) 14 | 15 | # find two solutions 16 | sol1 = (-b-cmath.sqrt(d))/(2*a) 17 | sol2 = (-b+cmath.sqrt(d))/(2*a) 18 | 19 | print('The solution are {0} and {1}'.format(sol1,sol2)) 20 | -------------------------------------------------------------------------------- /C/Factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int number; 5 | long long factorial; 6 | 7 | printf("Enter an integer: "); 8 | scanf("%d",&number); 9 | 10 | factorial = 1; 11 | 12 | // loop terminates when number is less than or equal to 0 13 | while (number > 0) 14 | { 15 | factorial *= number; // factorial = factorial*number; 16 | --number; 17 | } 18 | 19 | printf("Factorial= %lld", factorial); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C#/Star Pattern.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace starpattern 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | int i, j; 10 | for (i = 1; i <= 5; i++) 11 | { 12 | for (j = 1; j <= i; j++) 13 | { 14 | Console.Write("*"); 15 | } 16 | Console.WriteLine(); 17 | } 18 | Console.ReadLine(); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /C/Length Converter.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | float cm, m, km; 8 | 9 | /* get input in centimeter from user */ 10 | printf("Enter length in centimeter: "); 11 | scanf("%f", &cm); 12 | 13 | /* Convert centimeter value into meter and kilometer */ 14 | m = cm / 100.0; 15 | km = cm / 100000.0; 16 | 17 | printf("Length in Meter = %.2f m \n", m); 18 | printf("Length in Kilometer = %.2f km", km); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /C#/Reverse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | public class Reverse 3 | { 4 | public static void Main(string[] args) 5 | { 6 | int n, reverse=0, rem; 7 | Console.Write("Enter a number: "); 8 | n= int.Parse(Console.ReadLine()); 9 | while(n!=0) 10 | { 11 | rem=n%10; 12 | reverse=reverse*10+rem; 13 | n/=10; 14 | } 15 | Console.Write("Reversed Number: "+reverse); 16 | } 17 | } -------------------------------------------------------------------------------- /R/random.R: -------------------------------------------------------------------------------- 1 | ## 500 random numbers with normal distribution 2 | rnorm(500) 3 | 4 | #Random number with normal distribution using mean and standard deviation 5 | rnorm(500,mean=10,sd=1); 6 | 7 | # 500 random numbers between 0 and 100 8 | runif(500, min=0, max=100); 9 | 10 | #Random sample of 3 numbers in the range of 0 to 100 with replacement 11 | sample(1:100, 3, replace=TRUE) 12 | 13 | #visualize numbers distribution in a histogram 14 | hist(rnorm(500)); 15 | 16 | #density 17 | plot(density(runif(500, min=0, max=100))); -------------------------------------------------------------------------------- /javascript/helloworld.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Hello World 9 | 10 | 11 | 12 |

My First Web Page

13 | 14 | 18 | 19 | -------------------------------------------------------------------------------- /Python/Factorial.py: -------------------------------------------------------------------------------- 1 | # Python program to find the factorial of a number provided by the user. 2 | 3 | # change the value for a different result 4 | num = int(input('enter the number\n')) 5 | 6 | 7 | factorial = 1 8 | 9 | # check if the number is negative, positive or zero 10 | if num < 0: 11 | print("Sorry, factorial does not exist for negative numbers") 12 | elif num == 0: 13 | print("The factorial of 0 is 1") 14 | else: 15 | for i in range(1,num + 1): 16 | factorial *= i 17 | print("The factorial of",num,"is",factorial) 18 | -------------------------------------------------------------------------------- /Python/Star Pattern.py: -------------------------------------------------------------------------------- 1 | # Python 3.x code to demonstrate star pattern 2 | 3 | # Function to demonstrate printing pattern 4 | def pypart(n): 5 | 6 | # outer loop to handle number of rows 7 | # n in this case 8 | for i in range(0, n): 9 | 10 | # inner loop to handle number of columns 11 | # values changing acc. to outer loop 12 | for j in range(0, i+1): 13 | 14 | # printing stars 15 | print("* ",end="") 16 | 17 | # ending line after each row 18 | print("\r") 19 | 20 | # Driver Code 21 | n = 5 22 | pypart(n) 23 | -------------------------------------------------------------------------------- /C/AddInt.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int firstNumber, secondNumber, sumOfTwoNumbers; 5 | 6 | printf("Enter two integers: "); 7 | 8 | // Two integers entered by user is stored using scanf() function 9 | scanf("%d %d", &firstNumber, &secondNumber); 10 | 11 | // sum of two numbers in stored in variable sumOfTwoNumbers 12 | sumOfTwoNumbers = firstNumber + secondNumber; 13 | 14 | // Displays sum 15 | printf("%d + %d = %d", firstNumber, secondNumber, sumOfTwoNumbers); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /HTML/SignIn.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Login Form 5 | 6 | 7 |
8 |

Sign In

9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
User Name:
Password:
25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /Python/Caesar_cipher.py: -------------------------------------------------------------------------------- 1 | s=int(input("Select 1 for Encrypting select 2 for Decrypting : ")) 2 | if s==1: 3 | 4 | x=[i for i in input("Enter String to Encrypt : ").split(" ")] 5 | y=int(input("Enter Shifting Number : ")) 6 | for i in x: 7 | print("".join(chr(ord(j)+y) for j in i)) 8 | 9 | elif s==2: 10 | x=[i for i in input("Enter String to Decrypt : ").split(" ")] 11 | y=int(input("Enter Shifted Number : ")) 12 | for i in x: 13 | print("".join(chr(ord(j)-y) for j in i)) 14 | 15 | else: 16 | print("INVALID SELECTION") 17 | -------------------------------------------------------------------------------- /C#/Fibonacci.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | public class Fibonacci 3 | { 4 | public static void Main(string[] args) 5 | { 6 | int n1=0,n2=1,n3,i,number; 7 | Console.Write("Enter the number of elements: "); 8 | number = int.Parse(Console.ReadLine()); 9 | Console.Write(n1+" "+n2+" "); 10 | for(i=2;i 2 | int main() 3 | { 4 | int n1, n2, minMultiple; 5 | printf("Enter two positive integers: "); 6 | scanf("%d %d", &n1, &n2); 7 | 8 | // maximum number between n1 and n2 is stored in minMultiple 9 | minMultiple = (n1>n2) ? n1 : n2; 10 | 11 | // Always true 12 | while(1) 13 | { 14 | if( minMultiple%n1==0 && minMultiple%n2==0 ) 15 | { 16 | printf("The LCM of %d and %d is %d.", n1, n2,minMultiple); 17 | break; 18 | } 19 | ++minMultiple; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C/Multiply two numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | double firstNumber, secondNumber, product; 5 | printf("Enter two numbers: "); 6 | 7 | // Stores two floating point numbers in variable firstNumber and secondNumber respectively 8 | scanf("%lf %lf", &firstNumber, &secondNumber); 9 | 10 | // Performs multiplication and stores the result in variable productOfTwoNumbers 11 | product = firstNumber * secondNumber; 12 | 13 | // Result up to 2 decimal point is displayed using %.2lf 14 | printf("Product = %.2lf", product); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Python/Prime_Numb.py: -------------------------------------------------------------------------------- 1 | # Python program to check if the input number is prime or not 2 | 3 | num = 404 4 | 5 | # take input from the user 6 | # num = int(input("Enter a number: ")) 7 | 8 | # prime numbers are greater than 1 9 | if num > 1: 10 | # check for factors 11 | for i in range(2,num): 12 | if (num % i) == 0: 13 | print(num,"is not a prime number") 14 | print(i,"times",num//i,"is",num) 15 | break 16 | else: 17 | print(num,"is a prime number") 18 | 19 | # if input number is less than 20 | # or equal to 1, it is not prime 21 | else: 22 | print(num,"is not a prime number") -------------------------------------------------------------------------------- /C/pascalpyramid.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int rows, coef = 1, space, i, j; 5 | 6 | printf("Enter number of rows: "); 7 | scanf("%d",&rows); 8 | 9 | for(i=0; i 0: 29 | print(a * "*") 30 | a = a - 1 31 | 32 | 33 | star(a, b) 34 | 35 | -------------------------------------------------------------------------------- /C#/Decimal_Binary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | public class Decimal_Binary 3 | { 4 | public static void Main(string[] args) 5 | { 6 | int n, i; 7 | int[] a = new int[10]; 8 | Console.Write("Enter the number to convert: "); 9 | n= int.Parse(Console.ReadLine()); 10 | for(i=0; n>0; i++) 11 | { 12 | a[i]=n%2; 13 | n= n/2; 14 | } 15 | Console.Write("Binary of the given number= "); 16 | for(i=i-1 ;i>=0 ;i--) 17 | { 18 | Console.Write(a[i]); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /C++/LCSRecursive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int LCS(string X, string Y, int x, int y) 6 | { 7 | if (x == 0 || y == 0) 8 | return 0; 9 | 10 | else if (X[x - 1] != Y[y - 1]) 11 | return max(LCS(X, Y, x - 1, y), LCS(X, Y, x, y - 1)); 12 | 13 | else 14 | return 1 + LCS(X, Y, x - 1, y - 1); 15 | } 16 | 17 | int main(int argc, char const *argv[]) 18 | { 19 | string X, Y; 20 | cin >> X >> Y; 21 | 22 | int x, y; 23 | x = X.length(); 24 | y = Y.length(); 25 | 26 | int result = LCS(X, Y, x, y); 27 | cout << result; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Scala/Queue.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.immutable._ 2 | object MainObject{ 3 | def main(args:Array[String]){ 4 | var queue = Queue(1,5,6,2,3,9,5,2,5) 5 | print("Queue Elements: ") 6 | queue.foreach((element:Int)=>print(element+" ")) 7 | var firstElement = queue.front 8 | print("\nFirst element in the queue: "+ firstElement) 9 | var enqueueQueue = queue.enqueue(100) 10 | print("\nElement added in the queue: ") 11 | enqueueQueue.foreach((element:Int)=>print(element+" ")) 12 | var dequeueQueue = queue.dequeue 13 | print("\nElement deleted from this queue: "+ dequeueQueue) 14 | } 15 | } -------------------------------------------------------------------------------- /C++/ceaser.cpp: -------------------------------------------------------------------------------- 1 | //program to decrypt ceaser cipher 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | string s; 8 | cin>>s; 9 | //the most common letter in the english alphabet is e 10 | map fre; 11 | for(int i=0;ifirst)); 20 | string fin; 21 | for(int i=0;i 2 | int main() 3 | { 4 | int n, reversedInteger = 0, remainder, originalInteger; 5 | 6 | printf("Enter an integer: "); 7 | scanf("%d", &n); 8 | 9 | originalInteger = n; 10 | 11 | // reversed integer is stored in variable 12 | while( n!=0 ) 13 | { 14 | remainder = n%10; 15 | reversedInteger = reversedInteger*10 + remainder; 16 | n /= 10; 17 | } 18 | 19 | // palindrome if orignalInteger and reversedInteger are equal 20 | if (originalInteger == reversedInteger) 21 | printf("%d is a palindrome.", originalInteger); 22 | else 23 | printf("%d is not a palindrome.", originalInteger); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /C/VowelCons.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char c; 5 | int isLowercaseVowel, isUppercaseVowel; 6 | 7 | printf("Enter an alphabet: "); 8 | scanf("%c",&c); 9 | 10 | // evaluates to 1 (true) if c is a lowercase vowel 11 | isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); 12 | 13 | // evaluates to 1 (true) if c is an uppercase vowel 14 | isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); 15 | 16 | // evaluates to 1 (true) if either isLowercaseVowel or isUppercaseVowel is true 17 | if (isLowercaseVowel || isUppercaseVowel) 18 | printf("%c is a vowel.", c); 19 | else 20 | printf("%c is a consonant.", c); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C++/Operator_Overloading: -------------------------------------------------------------------------------- 1 | // CPP program to illustrate 2 | // Operator Overloading 3 | #include 4 | using namespace std; 5 | 6 | class Complex { 7 | private: 8 | int real, imag; 9 | public: 10 | Complex(int r = 0, int i =0) {real = r; imag = i;} 11 | 12 | // This is automatically called when '+' is used with 13 | // between two Complex objects 14 | Complex operator + (Complex const &obj) { 15 | Complex res; 16 | res.real = real + obj.real; 17 | res.imag = imag + obj.imag; 18 | return res; 19 | } 20 | void print() { cout << real << " + i" << imag << endl; } 21 | }; 22 | 23 | int main() 24 | { 25 | Complex c1(10, 5), c2(2, 4); 26 | Complex c3 = c1 + c2; // An example call to "operator+" 27 | c3.print(); 28 | } 29 | -------------------------------------------------------------------------------- /C/PerfectSquare.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); 5 | 6 | // variable declaration 7 | int i, number; 8 | 9 | // take user input 10 | printf("Enter a number: "); 11 | scanf("%d", &number); 12 | 13 | // loop to check number is perfect square or not 14 | for(i = 0; i <= number; i++) 15 | { 16 | if(number == i*i) 17 | { 18 | printf("\n\n\n\t\t\t%d is a perfect square\n\n\n", number); 19 | 20 | printf("\n\n\t\t\tCoding is Fun !\n\n\n"); 21 | return 0; // same as using break in this case to end the program 22 | } 23 | } 24 | printf("\n\n\n\t\t\t%d is not a perfect square\n", number); 25 | printf("\n\n\t\t\tCoding is Fun !\n\n\n"); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Java/Temp.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Temp { // convertion of fahrenheit to celcius and vise versa 4 | 5 | public static void main(String[] args) { 6 | double celcius, fahrenheit; 7 | Scanner in = new Scanner(System.in); 8 | 9 | System.out.print("Enter the value of temperature in degree celcius: "); 10 | celcius = in.nextDouble(); 11 | fahrenheit = celcius * 9 / 5 + 32; // convertion formula for celcius to fahrenheit 12 | System.out.printf(celcius+" °C = %.1f °F\n", fahrenheit); 13 | 14 | System.out.print("Now enter the value of temperature in degree fahrenheit: "); 15 | fahrenheit = in.nextDouble(); 16 | celcius = (fahrenheit - 32) * 5 / 9; // formula of fahrenheit to celcius 17 | System.out.printf(fahrenheit +" °F = %.1f °C\n", celcius); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Java/InsertionSort.java: -------------------------------------------------------------------------------- 1 | package InsertionSort; 2 | 3 | /** 4 | * InsertionSort 5 | */ 6 | public class InsertionSort { 7 | public static void main(String[] args) { 8 | int[] originalArray = new int[10]; 9 | 10 | for (int i = 0; i < originalArray.length; i++) { 11 | originalArray[i] = (int) (Math.random() * 15); 12 | } 13 | 14 | insertionSort(originalArray); 15 | 16 | for (int i = 0; i < originalArray.length; i++) { 17 | System.out.println(originalArray[i]); 18 | } 19 | } 20 | 21 | public static void insertionSort(int[] array) { 22 | for (int i = 1; i < array.length; i++) { 23 | int current = array[i]; 24 | int j = i - 1; 25 | while (j >= 0 && current < array[j]) { 26 | array[j + 1] = array[j]; 27 | j--; 28 | } 29 | array[j + 1] = current; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Java/LeapYear.java: -------------------------------------------------------------------------------- 1 | public class LeapYear { 2 | public static void main(String[] args) { 3 | int year = 1900; 4 | boolean leap = false; 5 | if(year % 4 == 0) 6 | { 7 | if( year % 100 == 0) 8 | { 9 | // year is divisible by 400, hence the year is a leap year 10 | if ( year % 400 == 0) 11 | leap = true; 12 | else 13 | leap = false; 14 | } 15 | else 16 | leap = true; 17 | } 18 | else 19 | leap = false; 20 | if(leap) 21 | System.out.println(year + " is a leap year."); 22 | else 23 | System.out.println(year + " is not a leap year."); 24 | } 25 | } -------------------------------------------------------------------------------- /Java/TOH.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | 5 | class TOH { 6 | public static void main(String[] args) throws IOException { 7 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | int n = Integer.parseInt(br.readLine()); 9 | towerOfHanoi(n, 'A', 'C', 'B'); 10 | } 11 | 12 | static void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod) 13 | { 14 | if (n == 1) 15 | { 16 | System.out.println("Move disk 1 from rod " + from_rod + " to rod " + to_rod); 17 | return; 18 | } 19 | towerOfHanoi(n-1, from_rod, aux_rod, to_rod); 20 | System.out.println("Move disk " + n + " from rod " + from_rod + " to rod " + to_rod); 21 | towerOfHanoi(n-1, aux_rod, to_rod, from_rod); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Python/magic.py: -------------------------------------------------------------------------------- 1 | # Import the modules 2 | import sys 3 | import random 4 | 5 | ans = True 6 | 7 | while ans: 8 | question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ") 9 | 10 | answers = random.randint(1,8) 11 | 12 | if question == "": 13 | sys.exit() 14 | 15 | elif answers == 1: 16 | print "It is certain" 17 | 18 | elif answers == 2: 19 | print "Outlook good" 20 | 21 | elif answers == 3: 22 | print "You may rely on it" 23 | 24 | elif answers == 4: 25 | print "Ask again later" 26 | 27 | elif answers == 5: 28 | print "Concentrate and ask again" 29 | 30 | elif answers == 6: 31 | print "Reply hazy, try again" 32 | 33 | elif answers == 7: 34 | print "My reply is no" 35 | 36 | elif answers == 8: 37 | print "My sources say no" 38 | -------------------------------------------------------------------------------- /Java/SortArray.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class SortArray 3 | { 4 | public static void main(String[] args) 5 | { 6 | int n, temp; 7 | Scanner s = new Scanner(System.in); 8 | System.out.print("Enter no. of elements you want in array:"); 9 | n = s.nextInt(); 10 | int a[] = new int[n]; 11 | System.out.println("Enter all the elements:"); 12 | for (int i=0; ia[j]) // compare numbers 21 | { 22 | temp=a[i]; 23 | a[i]=a[j]; 24 | a[j]=temp; 25 | } 26 | } 27 | } 28 | System.out.print("Elements in Ascending Order:"); 29 | for (int i=0; i 2 | #include 3 | 4 | int main() 5 | { 6 | char x; 7 | 8 | printf("Enter a text :"); 9 | scanf("%c",&x); 10 | 11 | switch(x) 12 | { 13 | case 'a' : printf("It's a Vowel"); 14 | break; 15 | case 'e' : printf("It's a Vowel"); 16 | break; 17 | case 'i' : printf("It's a Vowel"); 18 | break; 19 | case 'o' : printf("It's a Vowel"); 20 | break; 21 | case 'u' : printf("It's a Vowel"); 22 | break; 23 | case 'A' : printf("It's a Vowel"); 24 | break; 25 | case 'E' : printf("It's a Vowel"); 26 | break; 27 | case 'I' : printf("It's a Vowel"); 28 | break; 29 | case 'O' : printf("It's a Vowel"); 30 | break; 31 | case 'U' : printf("It's a Vowel"); 32 | break; 33 | default : printf("It's not a vowel"); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Python/dfs_graph.py: -------------------------------------------------------------------------------- 1 | class Graph(object): 2 | def __init__(self, vertices): 3 | self.vertices = vertices 4 | self.adjacency = [[] for _ in range(vertices)] 5 | 6 | def addEdge(self, i, vertex): 7 | self.adjacency[i].append(vertex) 8 | 9 | def dfs(self, vertex): 10 | visited = [False for _ in range(self.vertices)] 11 | self._dfs(vertex, visited) 12 | 13 | def _dfs(self, vertex, visited): 14 | print(vertex) 15 | visited[vertex] = True 16 | for i in self.adjacency[vertex]: 17 | if not visited[i]: 18 | self._dfs(i, visited) 19 | 20 | # Testing the code, values taken from https://www.geeksforgeeks.org/depth-first-search-or-dfs-for-a-graph/ 21 | g = Graph(4) 22 | g.addEdge(0, 1) 23 | g.addEdge(0, 2) 24 | g.addEdge(1, 2) 25 | g.addEdge(2, 0) 26 | g.addEdge(2, 3) 27 | g.addEdge(3, 3) 28 | print('Following is Depth First Traversal (starting from vertex 2)') 29 | g.dfs(2) -------------------------------------------------------------------------------- /C/ConcatString.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); 6 | char aa[100], bb[100]; 7 | 8 | printf("\nEnter the first string: "); 9 | gets(aa); // inputting first string 10 | 11 | printf("\nEnter the second string to be concatenated: "); 12 | gets(bb); // inputting second string 13 | 14 | char *a = aa; 15 | char *b = bb; 16 | 17 | // pointing to the end of the 1st string 18 | while(*a) // till it doesn't point to NULL-till string is not empty 19 | { 20 | a++; // point to the next letter of the string 21 | } 22 | while(*b) // till second string is not empty 23 | { 24 | *a = *b; 25 | b++; 26 | a++; 27 | } 28 | *a = '\0'; // string must end with '\0' 29 | printf("\n\n\nThe string after concatenation is: %s ", aa); 30 | printf("\n\n\t\t\tCoding is Fun !\n\n\n"); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /C#/palindrome.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Algorithms.Polindrome 4 | { 5 | public class Program 6 | { 7 | public static void Main(string[] args) 8 | { 9 | var str1 = "100001"; 10 | Console.WriteLine($"Is {str1} palindrome = {IsPalindrome(str1)}."); 11 | 12 | var str2 = "abcde"; 13 | Console.WriteLine($"Is {str2} palindrome = {IsPalindrome(str2)}."); 14 | 15 | var str3 = "lol"; 16 | Console.WriteLine($"Is {str3} palindrome = {IsPalindrome(str3)}."); 17 | } 18 | 19 | public static bool IsPalindrome(string str) 20 | { 21 | var length = str.Length; 22 | var halfLength = length / 2; 23 | 24 | for (int i = 0; i < halfLength; i++) 25 | if (str[i] != str[length - i - 1]) 26 | return false; 27 | 28 | return true; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Go/prime_check.go: -------------------------------------------------------------------------------- 1 | package primecheck 2 | 3 | // A primality test is an algorithm for determining whether an input number is prime.Among other fields of mathematics, it is used for cryptography. 4 | //Unlike integer factorization, primality tests do not generally give prime factors, only stating whether the input number is prime or not. 5 | //Source - Wikipedia https://en.wikipedia.org/wiki/Primality_test 6 | 7 | // NaiveApproach checks if an integer is prime or not. Returns a bool. 8 | func NaiveApproach(n int) bool { 9 | if n < 2 { 10 | return false 11 | } 12 | for i := 2; i < n; i++ { 13 | 14 | if n%i == 0 { 15 | return false 16 | } 17 | } 18 | return true 19 | } 20 | 21 | // PairApproach checks primality of an integer and returns a bool. More efficient than the naive approach as number of iterations are less. 22 | func PairApproach(n int) bool { 23 | if n < 2 { 24 | return false 25 | } 26 | for i := 2; i*i <= n; i++ { 27 | if n%i == 0 { 28 | return false 29 | } 30 | } 31 | return true 32 | } 33 | -------------------------------------------------------------------------------- /Python/Calculator.py: -------------------------------------------------------------------------------- 1 | # This function adds two numbers 2 | def add(x, y): 3 | return x + y 4 | 5 | # This function subtracts two numbers 6 | def subtract(x, y): 7 | return x - y 8 | 9 | # This function multiplies two numbers 10 | def multiply(x, y): 11 | return x * y 12 | 13 | # This function divides two numbers 14 | def divide(x, y): 15 | return x / y 16 | 17 | print("Select operation.") 18 | print("1.Add") 19 | print("2.Subtract") 20 | print("3.Multiply") 21 | print("4.Divide") 22 | 23 | # Take input from the user 24 | choice = input("Enter choice(1/2/3/4):") 25 | 26 | num1 = int(input("Enter first number: ")) 27 | num2 = int(input("Enter second number: ")) 28 | 29 | if choice == '1': 30 | print(num1,"+",num2,"=", add(num1,num2)) 31 | 32 | elif choice == '2': 33 | print(num1,"-",num2,"=", subtract(num1,num2)) 34 | 35 | elif choice == '3': 36 | print(num1,"*",num2,"=", multiply(num1,num2)) 37 | 38 | elif choice == '4': 39 | print(num1,"/",num2,"=", divide(num1,num2)) 40 | else: 41 | print("Invalid input") -------------------------------------------------------------------------------- /C/Switch_Cal.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | 3 | char operator; 4 | double firstNumber,secondNumber; 5 | 6 | printf("Enter an operator (+, -, *, /): "); 7 | scanf("%c", &operator); 8 | 9 | printf("Enter two operands: "); 10 | scanf("%lf %lf",&firstNumber, &secondNumber); 11 | 12 | switch(operator) 13 | { 14 | case '+': 15 | printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber+secondNumber); 16 | break; 17 | 18 | case '-': 19 | printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber-secondNumber); 20 | break; 21 | 22 | case '*': 23 | printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber*secondNumber); 24 | break; 25 | 26 | case '/': 27 | printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber/secondNumber); 28 | break; 29 | 30 | // operator is doesn't match any case constant (+, -, *, /) 31 | default: 32 | printf("Error! operator is not correct"); 33 | } 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /C/calculator_C.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | 3 | char operator; 4 | double firstNumber,secondNumber; 5 | 6 | printf("Enter an operator (+, -, *,): "); 7 | scanf("%c", &operator); 8 | 9 | printf("Enter two operands: "); 10 | scanf("%lf %lf",&firstNumber, &secondNumber); 11 | 12 | switch(operator) 13 | { 14 | case '+': 15 | printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber + secondNumber); 16 | break; 17 | 18 | case '-': 19 | printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber - secondNumber); 20 | break; 21 | 22 | case '*': 23 | printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber * secondNumber); 24 | break; 25 | 26 | case '/': 27 | printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber / secondNumber); 28 | break; 29 | 30 | // operator doesn't match any case constant (+, -, *, /) 31 | default: 32 | printf("Error! operator is not correct"); 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Java/Vector.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Vector { 4 | 5 | public static void main(String args[]) { 6 | /* Vector of initial capacity(size) of 2 */ 7 | Vector vec = new Vector(2); 8 | 9 | /* Adding elements to a vector*/ 10 | vec.addElement("Apple"); 11 | vec.addElement("Orange"); 12 | vec.addElement("Mango"); 13 | vec.addElement("Fig"); 14 | 15 | /* check size and capacityIncrement*/ 16 | System.out.println("Size is: "+vec.size()); 17 | System.out.println("Default capacity increment is: "+vec.capacity()); 18 | 19 | vec.addElement("fruit1"); 20 | vec.addElement("fruit2"); 21 | vec.addElement("fruit3"); 22 | 23 | /*size and capacityIncrement after two insertions*/ 24 | System.out.println("Size after addition: "+vec.size()); 25 | System.out.println("Capacity after increment is: "+vec.capacity()); 26 | 27 | /*Display Vector elements*/ 28 | Enumeration en = vec.elements(); 29 | System.out.println("\nElements are:"); 30 | while(en.hasMoreElements()) 31 | System.out.print(en.nextElement() + " "); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /C/SparseMatrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); 6 | int n, m, c, d, matrix[10][10]; 7 | int counter = 0; 8 | printf("\nEnter the number of rows and columns of the matrix \n\n"); 9 | scanf("%d%d",&m,&n); 10 | 11 | printf("\nEnter the %d elements of the matrix \n\n", m*n); 12 | for(c = 0; c < m; c++) // to iterate the rows 13 | { 14 | for(d = 0; d < n; d++) // to iterate the columns 15 | { 16 | scanf("%d", &matrix[c][d]); 17 | if(matrix[c][d] == 0) 18 | counter++; // same as counter=counter +1 19 | } 20 | } 21 | 22 | // printing the matrix 23 | printf("\n\nThe entered matrix is: \n\n"); 24 | for(c = 0; c < m; c++) // to iterate the rows 25 | { 26 | for(d = 0; d < n; d++) // to iterate the columns 27 | { 28 | printf("%d\t", matrix[c][d]); 29 | } 30 | printf("\n"); // to take the control to the next row 31 | } 32 | 33 | // checking if the matrix is sparse or not 34 | if(counter > (m*n)/2) 35 | printf("\n\nThe entered matrix is a sparse matrix\n\n"); 36 | else 37 | printf("\n\nThe entered matrix is not a sparse matrix\n\n"); 38 | 39 | printf("\n\n\t\t\tCoding is Fun !\n\n\n"); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Java/Calculator.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Calculator { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner reader = new Scanner(System.in); 8 | System.out.print("Enter two numbers: "); 9 | 10 | // nextDouble() reads the next double from the keyboard 11 | double first = reader.nextDouble(); 12 | double second = reader.nextDouble(); 13 | 14 | System.out.print("Enter an operator (+, -, *, /): "); 15 | char operator = reader.next().charAt(0); 16 | 17 | double result; 18 | 19 | switch(operator) 20 | { 21 | case '+': 22 | result = first + second; 23 | break; 24 | 25 | case '-': 26 | result = first - second; 27 | break; 28 | 29 | case '*': 30 | result = first * second; 31 | break; 32 | 33 | case '/': 34 | result = first / second; 35 | break; 36 | 37 | // operator doesn't match any case constant (+, -, *, /) 38 | default: 39 | System.out.println("Error! operator is not correct"); 40 | return; 41 | } 42 | 43 | System.out.println("%.1f %c %.1f = %.1f", first, operator, second, result); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Go/calculator.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "errors" 6 | "fmt" 7 | "os" 8 | "strconv" 9 | "strings" 10 | ) 11 | 12 | func parseArgs(c []string) (float64, float64, error) { 13 | num1, err := strconv.ParseFloat(c[0], 64) 14 | if err != nil { 15 | return 0.0, 0.0, err 16 | } 17 | num2, err := strconv.ParseFloat(c[2], 64) 18 | if err != nil { 19 | return 0.0, 0.0, err 20 | } 21 | return num1, num2, nil 22 | } 23 | 24 | func processStack(e []string) (float64, error) { 25 | result := 0.0 26 | for _, v := range e { 27 | c := strings.Split(v, " ") 28 | if len(c)-1 < 2 { 29 | return 0.0, errors.New("error: some arguments are not supplied") 30 | } 31 | num1, num2, err := parseArgs(c) 32 | if err != nil { 33 | return 0.0, err 34 | } 35 | switch c[1] { 36 | case "*": 37 | result = num1 * num2 38 | case "/": 39 | if num2 == 0.0 { 40 | return 0.0, errors.New("error: you tried to divide by zero.") 41 | } 42 | result = num1 / num2 43 | case "+": 44 | result = num1 + num2 45 | case "-": 46 | result = num1 - num2 47 | } 48 | } 49 | return result, nil 50 | } 51 | 52 | func main() { 53 | expressions := make([]string, 1) 54 | for { 55 | scanner := bufio.NewScanner(os.Stdin) 56 | fmt.Print("gocalc>") 57 | for scanner.Scan() { 58 | expressions = append(expressions, scanner.Text()) 59 | res, err := processStack(expressions) 60 | if err != nil { 61 | fmt.Println(err) 62 | } else { 63 | fmt.Println(res) 64 | } 65 | fmt.Print("gocalc>") 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /C/QueueExample.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define SIZE 5 3 | 4 | void enQueue(int); 5 | void deQueue(); 6 | void display(); 7 | 8 | int items[SIZE], front = -1, rear = -1; 9 | 10 | int main() 11 | { 12 | //deQueue is not possible on empty queue 13 | deQueue(); 14 | 15 | //enQueue 5 elements 16 | enQueue(1); 17 | enQueue(2); 18 | enQueue(3); 19 | enQueue(4); 20 | enQueue(5); 21 | 22 | //6th element can't be added to queue because queue is full 23 | enQueue(6); 24 | 25 | display(); 26 | 27 | //deQueue removes element entered first i.e. 1 28 | deQueue(); 29 | 30 | //Now we have just 4 elements 31 | display(); 32 | 33 | return 0; 34 | 35 | } 36 | 37 | void enQueue(int value){ 38 | if(rear == SIZE-1) 39 | printf("\nQueue is Full!!"); 40 | else { 41 | if(front == -1) 42 | front = 0; 43 | rear++; 44 | items[rear] = value; 45 | printf("\nInserted -> %d", value); 46 | } 47 | } 48 | 49 | void deQueue(){ 50 | if(front == -1) 51 | printf("\nQueue is Empty!!"); 52 | else{ 53 | printf("\nDeleted : %d", items[front]); 54 | front++; 55 | if(front > rear) 56 | front = rear = -1; 57 | } 58 | } 59 | 60 | void display(){ 61 | if(rear == -1) 62 | printf("\nQueue is Empty!!!"); 63 | else{ 64 | int i; 65 | printf("\nQueue elements are:\n"); 66 | for(i=front; i<=rear; i++) 67 | printf("%d\t",items[i]); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /C/ReverseStr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); 6 | 7 | char str[100]; 8 | char rev[100]; 9 | char *sptr = str; // sptr stores the base address of the str 10 | char *rptr = rev; // rptr stores the base address of the reverse 11 | 12 | int i = -1; 13 | 14 | printf("\n\nEnter a string: "); 15 | scanf("%s", str); 16 | 17 | // storing the ending address of str in sptr 18 | while(*sptr) 19 | { 20 | sptr++; 21 | i++; // i is the index of the end location 22 | } 23 | 24 | // storing the string str in rev in reverse order 25 | while(i >= 0) 26 | { 27 | /* 28 | First decrementing then using as it stores 29 | the location after the end location due to above while loop 30 | */ 31 | sptr--; 32 | *rptr = *sptr; // storing the value in sptr in rptr 33 | rptr++; // pointing to next location 34 | i--; // decrementing the index 35 | } 36 | /* 37 | String should always end with '\0' so explicitly 38 | putting it at the end of the string 39 | */ 40 | *rptr = '\0'; 41 | rptr = rev; // restoring the base address of the reverse string 42 | 43 | // storing the reverse string in the original string 44 | while(*rptr) 45 | { 46 | *sptr = *rptr; 47 | sptr++; 48 | rptr++; 49 | } 50 | 51 | // printing the reverse string 52 | printf("\n\nReverse of the string is: %s ", str); 53 | printf("\n\n\t\t\tCoding is Fun !\n\n\n"); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Java/LinkedList.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class LinkedList { 3 | public static void main(String args[]) { 4 | 5 | /* Linked List Declaration */ 6 | LinkedList linkedlist = new LinkedList(); 7 | 8 | /*add(String Element) is used for adding 9 | * the elements to the linked list*/ 10 | linkedlist.add("Item1"); 11 | linkedlist.add("Item5"); 12 | linkedlist.add("Item3"); 13 | linkedlist.add("Item6"); 14 | linkedlist.add("Item2"); 15 | 16 | /*Display Linked List Content*/ 17 | System.out.println("Linked List Content: " +linkedlist); 18 | 19 | /*Add First and Last Element*/ 20 | linkedlist.addFirst("First Item"); 21 | linkedlist.addLast("Last Item"); 22 | System.out.println("LinkedList Content after addition: " +linkedlist); 23 | 24 | /*This is how to get and set Values*/ 25 | Object firstvar = linkedlist.get(0); 26 | System.out.println("First element: " +firstvar); 27 | linkedlist.set(0, "Changed first item"); 28 | Object firstvar2 = linkedlist.get(0); 29 | System.out.println("First element after update by set method: " +firstvar2); 30 | 31 | /*Remove first and last element*/ 32 | linkedlist.removeFirst(); 33 | linkedlist.removeLast(); 34 | System.out.println("LinkedList after deletion of first and last element: " +linkedlist); 35 | 36 | /* Add to a Position and remove from a position*/ 37 | linkedlist.add(0, "Newly added item"); 38 | linkedlist.remove(2); 39 | System.out.println("Final Content: " +linkedlist); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Java/HeapSortAlgo.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | /** 5 | * @author Dipyaman Saha (https://github.com/dipyamansaha) - HEAP SORT ALGORITHM - 6 | * https://en.wikipedia.org/wiki/Heapsort 7 | */ 8 | public class HeapSortAlgo { 9 | static void HeapSort(int[] Arr) { 10 | int n = Arr.length; 11 | 12 | BuildMaxHeap(Arr); 13 | 14 | for (int i = (n - 1); i >= 0; i--) { 15 | int temp = Arr[0]; 16 | Arr[0] = Arr[i]; 17 | Arr[i] = temp; 18 | 19 | MaxHeapify(Arr, i, 0); 20 | } 21 | } 22 | 23 | static void MaxHeapify(int[] Arr, int n, int i) { 24 | int l = (2 * i + 1); 25 | int r = (2 * i + 2); 26 | 27 | int largest; 28 | 29 | if ((l < n) && (Arr[l] > Arr[i])) largest = l; 30 | else largest = i; 31 | 32 | if ((r < n) && (Arr[r] > Arr[largest])) largest = r; 33 | 34 | if (largest != i) { 35 | int temp = Arr[i]; 36 | Arr[i] = Arr[largest]; 37 | Arr[largest] = temp; 38 | 39 | MaxHeapify(Arr, n, largest); 40 | } 41 | } 42 | 43 | static void BuildMaxHeap(int[] Arr) { 44 | int n = Arr.length; 45 | 46 | for (int i = (n / 2 - 1); i >= 0; i--) MaxHeapify(Arr, n, i); 47 | } 48 | 49 | public static void main(String[] args) { 50 | System.out.println("HEAP SORT ALGORITHM\n"); 51 | 52 | Scanner sc = new Scanner(System.in); 53 | 54 | System.out.print("How many elements do you wanna insert? "); 55 | int n = sc.nextInt(); 56 | 57 | int[] Arr = new int[n]; 58 | 59 | System.out.println("Enter the elements: "); 60 | for (int i = 0; i < n; i++) { 61 | Arr[i] = sc.nextInt(); 62 | } 63 | 64 | System.out.println("The entered array: " + Arrays.toString(Arr)); 65 | 66 | HeapSort(Arr); 67 | System.out.println("The sorted array: " + Arrays.toString(Arr)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /C/Round Robin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define max 20 // maximum size for array 3 | int main() 4 | { 5 | int i,burstTime[max],remainTime[max],remainProcess,arrivalTime[max],totalExecutionTime=0,timeQuantum,flag=0,n; 6 | float totalWaitingTime=0; 7 | printf("Enter the Number of Process(max 20) : "); 8 | scanf("%d",&n); // n is the number of Process 9 | remainProcess=n; 10 | 11 | printf("Enter Arrival Time\n"); 12 | for(i=0;i0){ 30 | totalExecutionTime+=remainTime[i]; 31 | remainTime[i]=0; 32 | flag=1; 33 | } 34 | 35 | else if(remainTime[i]>0){ 36 | remainTime[i]-=timeQuantum; 37 | totalExecutionTime+=timeQuantum; 38 | } 39 | 40 | if(flag==1 && remainTime[i]==0){ 41 | printf("P[%d] | waiting Time : %d\n",i+1,totalExecutionTime-arrivalTime[i]-burstTime[i]); 42 | totalWaitingTime+=totalExecutionTime-arrivalTime[i]-burstTime[i]; 43 | flag=0; 44 | remainProcess--; 45 | } 46 | 47 | if(i==n-1) 48 | i=0; 49 | else if(arrivalTime[i+1]<=totalExecutionTime){ 50 | i++; 51 | } 52 | else 53 | i=0; 54 | } 55 | 56 | totalWaitingTime=(float)totalWaitingTime/n; 57 | printf("\nThe Average Waiting Time : %.2f \n",totalWaitingTime); 58 | 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Python/Hangman.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | #welcoming the user 4 | name = raw_input("What is your name? ") 5 | 6 | print "Hello, " + name, "Time to play hangman!" 7 | 8 | print " 9 | " 10 | 11 | #wait for 1 second 12 | time.sleep(1) 13 | 14 | print "Start guessing..." 15 | time.sleep(0.5) 16 | 17 | #here we set the secret 18 | word = "secret" 19 | 20 | #creates an variable with an empty value 21 | guesses = '' 22 | 23 | #determine the number of turns 24 | turns = 10 25 | 26 | # Create a while loop 27 | 28 | #check if the turns are more than zero 29 | while turns > 0: 30 | 31 | # make a counter that starts with zero 32 | failed = 0 33 | 34 | # for every character in secret_word 35 | for char in word: 36 | 37 | # see if the character is in the players guess 38 | if char in guesses: 39 | 40 | # print then out the character 41 | print char, 42 | 43 | else: 44 | 45 | # if not found, print a dash 46 | print "_", 47 | 48 | # and increase the failed counter with one 49 | failed += 1 50 | 51 | # if failed is equal to zero 52 | 53 | # print You Won 54 | if failed == 0: 55 | print " 56 | You won" 57 | 58 | # exit the script 59 | break 60 | 61 | print 62 | 63 | # ask the user go guess a character 64 | guess = raw_input("guess a character:") 65 | 66 | # set the players guess to guesses 67 | guesses += guess 68 | 69 | # if the guess is not found in the secret word 70 | if guess not in word: 71 | 72 | # turns counter decreases with 1 (now 9) 73 | turns -= 1 74 | 75 | # print wrong 76 | print "Wrong 77 | " 78 | 79 | # how many turns are left 80 | print "You have", + turns, 'more guesses' 81 | 82 | # if the turns are equal to zero 83 | if turns == 0: 84 | 85 | # print "You Loose" 86 | print "You Loose 87 | " 88 | -------------------------------------------------------------------------------- /Python/Linear Regression.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | #importing the required packages 8 | import pandas as pd 9 | import seaborn as sns 10 | import numpy as np 11 | from sklearn.metrics import mean_squared_error, r2_score 12 | from sklearn.linear_model import LinearRegression 13 | from sklearn.model_selection import train_test_split 14 | 15 | #reading the data 16 | dataset= pd.read_excel("C:/Users/ASUS/Linear Regression.xlsx", sheet_name="Linear Regression") 17 | 18 | #defined a function to take the independent variables as input 19 | def reg(col_name): 20 | 21 | #gaining insights about the data 22 | dataset.head() 23 | dataset.isnull().sum() 24 | dataset.describe() 25 | dataset.corr() 26 | print("for", col_name) 27 | sns.pairplot(dataset) 28 | print('---------------------------------------------------------------') 29 | 30 | #dividing the data into x and y 31 | x=dataset[[col_name]] 32 | y=dataset[['price']] 33 | 34 | #splitting the training data and testing data 35 | x_train,x_test,y_train,y_test= train_test_split(x,y,test_size=0.3,random_state=10) 36 | reg= LinearRegression() 37 | 38 | #fitting the model 39 | reg.fit(x_train,y_train) 40 | 41 | #predicting on the unseen data 42 | prediction= reg.predict(x_test) 43 | 44 | #getting the RMSE valuse and r2 value and printing them 45 | RMSE=np.sqrt(mean_squared_error(y_test,prediction)) 46 | r2=r2_score(y_test, prediction) 47 | #print("for", col_name) 48 | print("R Sqaure value is", r2) 49 | print("Root mean square is ", RMSE) 50 | 51 | #predicting and priniting the estimated price 52 | unseen_pred=reg.predict(np.array([[2]])) 53 | print("The estiamted price is",unseen_pred) 54 | print('---------------------------------------------------------------') 55 | 56 | #passing values (the independent varibles) to the function 57 | reg('sqft_living') 58 | reg('bedrooms') 59 | reg('bathrooms') 60 | reg('floors') 61 | 62 | 63 | # In[ ]: 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /HTML/htmldev.html: -------------------------------------------------------------------------------- 1 | data = $post_data; 11 | } 12 | 13 | public function validateForm(){ 14 | foreach(self::$fields as $field){ 15 | if(!array_key_exists($field, $this->data)){ 16 | trigger_error("$field is not present in data"); 17 | return; 18 | } 19 | } 20 | 21 | $this->validateUsername(); 22 | $this->validateEmail(); 23 | return $this->errors; 24 | } 25 | 26 | private function validateUsername(){ 27 | 28 | $val = trin($this->data['username']); 29 | 30 | if(empty($val)){ 31 | $this->addError('username', 'username cannot be empty'); 32 | }else{ 33 | if(!preg_match('/^[a-zA-Z0-9]{6,12}$/', $val)){ 34 | $this->addError('username', 'Username must be 6-12 chars and alphanumeric'); 35 | } 36 | } 37 | 38 | 39 | } 40 | 41 | validateForm(); 49 | 50 | // save data to db 51 | } 52 | 53 | 54 | ?> 55 | 56 | 57 | 58 | 59 | 60 | Document 61 | 62 | 63 | 64 | 65 |
66 |

Create New User

67 |
68 | 69 | 70 | 71 |
72 | 73 |
74 | 75 | 76 | 77 |
78 | 79 |
80 | 81 | 82 | 83 |
84 |
85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /C/First Come First Serve.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | typedef struct fcfs 5 | { 6 | int processno; //Process Number 7 | int processID; //Randomly generated Process ID 8 | int burst; //Burst Time 9 | int arrival; //Arrival Time 10 | int tat; //Turn Around Time 11 | int wt; //Waiting Time 12 | }fcfs; 13 | 14 | int sort(fcfs [], int); 15 | 16 | int main() 17 | { 18 | int n, i, temp = 0, AvTat = 0, AvWt = 0; 19 | int option; 20 | printf ("Enter the number of processes: "); 21 | scanf ("%d", &n); 22 | fcfs arr[n]; //Array of type fcfs 23 | int tct[n]; 24 | printf("AutoSelect zero for Arrival Time \nYes=>1\nNo =>0\n"); 25 | scanf("%d",&option); 26 | srand(time(0)); 27 | for (i = 0; i < n; i++) 28 | { 29 | arr[i].processno = i; 30 | arr[i].processID = rand(); 31 | printf ("Enter the process %d data\n", arr[i].processno); 32 | printf ("Enter CPU Burst: "); 33 | scanf ("%d", &(arr[i].burst)); 34 | if(option == 0){ 35 | printf ("Enter the arrival time: "); 36 | scanf ("%d", &(arr[i].arrival));} 37 | else{ 38 | arr[i].arrival = 0; 39 | } 40 | } 41 | 42 | //Sorting the processes according to their arrival time 43 | sort(arr, n); 44 | 45 | printf ("Process\t\tProcessID\t\tBurst Time\tArrival Time\tTurn Around Time\tWaiting Time\n"); 46 | for (i = 0; i < n; i++) 47 | { 48 | tct[i] = temp + arr[i].burst; 49 | temp = tct[i]; 50 | arr[i].tat = tct[i] - arr[i].arrival; 51 | arr[i].wt = arr[i].tat - arr[i].burst; 52 | AvTat = AvTat + arr[i].tat; 53 | AvWt = AvWt + arr[i].wt; 54 | printf ("%5d\t\t%5d\t%15d\t\t%9d\t%12d\t%12d\n", arr[i].processno,arr[i].processID,arr[i].burst, arr[i].arrival, arr[i].tat, arr[i].wt); 55 | } 56 | 57 | printf ("Average Turn Around Time: %d\nAverage Waiting Time: %d\n", AvTat / n, AvWt / n); 58 | 59 | return 0; 60 | } 61 | 62 | //Bubble Sort 63 | int sort(fcfs arr[], int n) 64 | { 65 | int i, j; 66 | fcfs k; 67 | 68 | for (i = 0; i < n - 1; i++) 69 | { 70 | for (j = i + 1; j < n; j++) 71 | { 72 | //Sorting the processes according to their arrival time 73 | if (arr[i].arrival > arr[j].arrival) 74 | { 75 | k = arr[i]; 76 | arr[i] = arr[j]; 77 | arr[j] = k; 78 | } 79 | } 80 | } 81 | return 0; 82 | } -------------------------------------------------------------------------------- /Java/priority_queue.java: -------------------------------------------------------------------------------- 1 | // Java code to implement Priority Queue 2 | // using Linked List 3 | import java.util.* ; 4 | 5 | class Solution 6 | { 7 | 8 | 9 | // Node 10 | static class Node { 11 | int data; 12 | 13 | // Lower values indicate higher priority 14 | int priority; 15 | 16 | Node next; 17 | 18 | } 19 | 20 | static Node node = new Node(); 21 | 22 | // Function to Create A New Node 23 | static Node newNode(int d, int p) 24 | { 25 | Node temp = new Node(); 26 | temp.data = d; 27 | temp.priority = p; 28 | temp.next = null; 29 | 30 | return temp; 31 | } 32 | 33 | // Return the value at head 34 | static int peek(Node head) 35 | { 36 | return (head).data; 37 | } 38 | 39 | // Removes the element with the 40 | // highest priority form the list 41 | static Node pop(Node head) 42 | { 43 | Node temp = head; 44 | (head) = (head).next; 45 | return head; 46 | } 47 | 48 | // Function to push according to priority 49 | static Node push(Node head, int d, int p) 50 | { 51 | Node start = (head); 52 | 53 | // Create new Node 54 | Node temp = newNode(d, p); 55 | 56 | // Special Case: The head of list has lesser 57 | // priority than new node. So insert new 58 | // node before head node and change head node. 59 | if ((head).priority > p) { 60 | 61 | // Insert New Node before head 62 | temp.next = head; 63 | (head) = temp; 64 | } 65 | else { 66 | 67 | // Traverse the list and find a 68 | // position to insert new node 69 | while (start.next != null && 70 | start.next.priority < p) { 71 | start = start.next; 72 | } 73 | 74 | // Either at the ends of the list 75 | // or at required position 76 | temp.next = start.next; 77 | start.next = temp; 78 | } 79 | return head; 80 | } 81 | 82 | // Function to check is list is empty 83 | static int isEmpty(Node head) 84 | { 85 | return ((head) == null)?1:0; 86 | } 87 | 88 | // Driver code 89 | public static void main(String args[]) 90 | { 91 | // Create a Priority Queue 92 | // 7.4.5.6 93 | Node pq = newNode(4, 1); 94 | pq =push(pq, 5, 2); 95 | pq =push(pq, 6, 3); 96 | pq =push(pq, 7, 0); 97 | 98 | while (isEmpty(pq)==0) { 99 | System.out.printf("%d ", peek(pq)); 100 | pq=pop(pq); 101 | } 102 | 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /C/curency.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | 3 | /*Declare floaters*/ 4 | 5 | float Swiss_Franc; /*Swiss Franc*/ 6 | float British_Pounds; /*British pounds*/ 7 | float Japanese_Yen; /*Japanese Yen*/ 8 | float Canadian_Dollar; /*Canadian Dollar*/ 9 | float Euros; /*European Union Euro*/ 10 | float USD; /*US Dollar*/ 11 | int choice; 12 | 13 | /*Title*/ 14 | 15 | printf(" Currency Conversion Program\n"); 16 | 17 | printf("----------------------------------------\n\n"); 18 | 19 | 20 | /*Menu*/ 21 | 22 | printf("1) Swiss Franc \n"); 23 | printf("2) British Pound \n"); 24 | printf("3) Japanese Yen \n"); 25 | printf("4) Canadian Dollar \n"); 26 | printf("5) Euro \n"); 27 | printf("6) Exit the Program \n"); 28 | 29 | 30 | printf("\n"); 31 | printf("\n"); 32 | 33 | /*Input from User*/ 34 | 35 | printf("Please enter your choice (1-6): "); 36 | scanf("%d",&choice); 37 | 38 | while((choice<1) || (choice>6)){ 39 | printf("Invalid entry, please Enter 1-6: "); 40 | scanf("%i",&choice); 41 | } 42 | if(choice==1){ 43 | printf("Please the amount: "); 44 | scanf("%f",&Swiss_Franc); 45 | 46 | /*Conversion Calculation 1*/ 47 | Swiss_Franc = USD / Swiss_Franc_rate; 48 | 49 | } 50 | if(choice==2){ 51 | printf("Please enter the amount: "); 52 | scanf("%f",&British_Pounds); 53 | 54 | /*Conversion Calculation 2*/ 55 | British_Pounds = USD / British_Pounds_rate; 56 | } 57 | 58 | if(choice==3){ 59 | printf("Please enter the amount: "); 60 | scanf("%f",&Japanese_Yen); 61 | 62 | /*Conversion Calculation 3*/ 63 | Japanese_Yen = USD / Japanese_Yen_rate 64 | } 65 | 66 | if(choice==4){ 67 | printf("Please enter the amount: "); 68 | scanf("%f",&Canadian_Dollar); 69 | 70 | /*Conversion Calculation 4*/ 71 | Canadian_Dollar = USD / Canadian_Dollar_rate; 72 | } 73 | 74 | if(choice==5){ 75 | printf("Please enter the amount: "); 76 | scanf("%f",&Euros); 77 | 78 | /*Conversion Calculation 5*/ 79 | Euros = USD / Euros_rate; 80 | } 81 | 82 | if(choice==6){ 83 | printf("Exit the program: "); 84 | 85 | while (getchar() != '\n') 86 | continue; 87 | goto top; 88 | } 89 | printf("Goodbye!\n"); 90 | return 0; 91 | 92 | } 93 | //Function 94 | 95 | void dashbar() 96 | { 97 | int i = 1; 98 | while (i < 50) 99 | { 100 | putchar ('-'); 101 | i = i + 1; 102 | } 103 | putchar ('\n'); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /Go/huffman.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sort" 5 | ) 6 | 7 | // HuffmanTree is a codification of a Huffman tree. We arbitrary decide that we interpret the left tree as bit 1 and 8 | // the right tree as bit 0. In the right part of the tree we store the values for the level, i.e. the nearer to the 9 | // root on the right side, the higher the frequency of the respective character in the stream. 10 | type HuffmanTree struct { 11 | Value byte 12 | Left *HuffmanTree 13 | Right *HuffmanTree 14 | } 15 | 16 | func (tree HuffmanTree) String() string { 17 | s1 := "" 18 | s2 := "" 19 | v := "" 20 | 21 | if !tree.isLeaf() { 22 | s1 = "right: " + tree.Right.String() 23 | // We assume that we always have a left tree if we have a right tree. 24 | s2 = ", left: " + tree.Left.String() 25 | } else { 26 | v = string(tree.Value) 27 | } 28 | 29 | return "{" + v + s1 + s2 + "}" 30 | } 31 | 32 | func (tree HuffmanTree) isLeaf() bool { 33 | return tree.Right == nil && tree.Left == nil 34 | } 35 | 36 | // GetCodebook returns the codebook for this particular tree. 37 | func (tree HuffmanTree) GetCodebook() map[byte][]int { 38 | m := make(map[byte][]int) 39 | 40 | path := make([]int, 0) 41 | for root := tree; root.Right != nil; root = *root.Left { 42 | curPath := append(path, 1) 43 | m[root.Right.Value] = curPath 44 | path = append(path, 0) 45 | 46 | // If we are at the last two elements, use 0 for the last element with the lowest frequency instead of 1. 47 | if root.Left.Right == nil { 48 | m[root.Left.Value] = path 49 | } 50 | } 51 | 52 | return m 53 | } 54 | 55 | // GenerateHuffmanTree generates a HuffmanTree based on the data passed in the parameter. 56 | func NewHuffmanTree(s []byte) HuffmanTree { 57 | frequencies := ComputeFrequency(s) 58 | byteList := SortFrequencyList(frequencies) 59 | 60 | // Combine single sorted lists to a single binary tree. 61 | root := makeLeaf(byteList[0]) 62 | for _, leafValue := range byteList[1:] { 63 | leaf := makeLeaf(leafValue) 64 | root = combineLeafs(root, leaf) 65 | } 66 | 67 | return root 68 | } 69 | 70 | // makeLeaf generate a single leaf without children. 71 | func makeLeaf(value byte) HuffmanTree { 72 | return HuffmanTree{Value: value} 73 | } 74 | 75 | // combineLeafs combines two trees into a single new one without a value. Note that we intentionally pass parameters 76 | // by value to have 'fresh' trees. 77 | func combineLeafs(left, right HuffmanTree) HuffmanTree { 78 | return HuffmanTree{0, &left, &right} 79 | } 80 | 81 | // SortFrequencyList generates a list of bytes sorted by relative frequency, starting with the smallest ones. 82 | func SortFrequencyList(m map[byte]float32) []byte { 83 | // Convert to array of struct values. 84 | type kv struct { 85 | Key byte 86 | Value float32 87 | } 88 | var kvs []kv 89 | for k, v := range m { 90 | kvs = append(kvs, kv{k, v}) 91 | } 92 | 93 | // Sort array. 94 | sort.Slice(kvs, func(i, j int) bool { 95 | return kvs[i].Value < kvs[j].Value 96 | }) 97 | 98 | // Convert to byte array. 99 | var result []byte 100 | for _, v := range kvs { 101 | result = append(result, v.Key) 102 | } 103 | return result 104 | } 105 | 106 | // ComputeFrequency computes a relative frequency map of all characters in the array. 107 | func ComputeFrequency(s []byte) map[byte]float32 { 108 | m := make(map[byte]float32) 109 | 110 | // Count absolute number. 111 | for _, v := range s { 112 | m[v]++ 113 | } 114 | // Compute relative number of occurrences. 115 | for k, v := range m { 116 | m[k] = v / float32(len(s)) 117 | } 118 | 119 | return m 120 | } 121 | -------------------------------------------------------------------------------- /php/signup.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 18 | 19 | 50 |
51 |
52 |
53 |
54 |
55 |

Signup

56 | Fill in all fields!

'; 60 | } 61 | else if ($_GET["eror"] == "invaliduidmail" ) { 62 | echo '

Invalid username and e-mail!

'; 63 | } 64 | else if ($_GET["eror"] == "invaliduid") { 65 | echo '

Invalid username

'; 66 | } 67 | else if ($_GET["eror"] == "invalidmail") { 68 | echo '

Invalid e-mail

'; 69 | } 70 | else if ($_GET["eror"] == "passwordcheck") { 71 | echo '

Your passwords do not match

'; 72 | } 73 | else if ($_GET["eror"] == "usertaken") { 74 | echo '

Username is already taken

'; 75 | } 76 | } 77 | // else if ($_GET["Signup"] == "success") { 78 | // echo '

Signup successful

'; 79 | // } 80 | ?> 81 | 100 |
101 |
102 | 103 |
104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /C++/fcfs.cpp: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | //First Comes First Serve(FCFS) 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | void Sort_by_arrival_time(int arrival_time[], int burst_time[], int n){ 9 | vector< pair > v; 10 | 11 | for (int i = 0; i < n; ++i){ 12 | v.push_back({arrival_time[i], burst_time[i]}); 13 | } 14 | 15 | sort(v.begin(), v.end()); 16 | 17 | for (int i = 0; i < n; ++i) 18 | { 19 | arrival_time[i] = v[i].first; 20 | burst_time[i] = v[i].second; 21 | } 22 | } 23 | 24 | void findWaitingTime(int processes[], int n, int bt[], int wt[]) { 25 | 26 | wt[0] = 0; 27 | for (int i = 1; i < n ; i++ ) 28 | wt[i] = bt[i-1] + wt[i-1] ; 29 | } 30 | 31 | void findTurnAroundTime( int processes[], int n, int bt[], int wt[], int tat[]) { 32 | for (int i = 0; i < n ; i++) 33 | tat[i] = bt[i] + wt[i]; 34 | } 35 | 36 | void findavgTime( int processes[], int n, int bt[]) { 37 | int wt[n], tat[n], total_wt = 0, total_tat = 0; 38 | 39 | findWaitingTime(processes, n, bt, wt); 40 | 41 | findTurnAroundTime(processes, n, bt, wt, tat); 42 | 43 | cout << "Processes "<< " Burst time " 44 | << " Waiting time " << " Turn around time\n"; 45 | for (int i=0; i 86 | 87 | using namespace std; 88 | 89 | void Sort_by_arrival_time(int arrival_time[], int burst_time[], int n){ 90 | vector< pair > v; 91 | 92 | for (int i = 0; i < n; ++i){ 93 | v.push_back({arrival_time[i], burst_time[i]}); 94 | } 95 | 96 | sort(v.begin(), v.end()); 97 | 98 | for (int i = 0; i < n; ++i) 99 | { 100 | arrival_time[i] = v[i].first; 101 | burst_time[i] = v[i].second; 102 | } 103 | } 104 | 105 | void findWaitingTime(int processes[], int n, int bt[], int wt[]) { 106 | 107 | wt[0] = 0; 108 | for (int i = 1; i < n ; i++ ) 109 | wt[i] = bt[i-1] + wt[i-1] ; 110 | } 111 | 112 | void findTurnAroundTime( int processes[], int n, int bt[], int wt[], int tat[]) { 113 | for (int i = 0; i < n ; i++) 114 | tat[i] = bt[i] + wt[i]; 115 | } 116 | 117 | void findavgTime( int processes[], int n, int bt[]) { 118 | int wt[n], tat[n], total_wt = 0, total_tat = 0; 119 | 120 | findWaitingTime(processes, n, bt, wt); 121 | 122 | findTurnAroundTime(processes, n, bt, wt, tat); 123 | 124 | cout << "Processes "<< " Burst time " 125 | << " Waiting time " << " Turn around time\n"; 126 | for (int i=0; i>>>>>> 2db113523ebbfb33ba57baa4f18f9baa62be7c49 164 | -------------------------------------------------------------------------------- /C#/Calculator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Text.RegularExpressions; 6 | 7 | namespace Arithmetic 8 | { 9 | class Program 10 | { 11 | //validate the input to a double data type 12 | static bool InputValidator(string input) 13 | { 14 | string pattern = "[^0-9][.]"; 15 | if (Regex.IsMatch(input, pattern)) 16 | { 17 | return true; 18 | } 19 | else 20 | { 21 | return false; 22 | } 23 | } 24 | //define your version of arithmetic methods 25 | static void add(double n1, double n2) 26 | { 27 | Console.WriteLine("The Result is:{0}\n",n1 + n2); 28 | } 29 | static void sub(double n1,double n2) 30 | { 31 | Console.WriteLine("The Result is:{0)\n",n1 - n2); 32 | } 33 | static void mult(double n1, double n2) 34 | { 35 | Console.WriteLine("The Result is:{0}\n", n1 * n2); 36 | } 37 | static void div(double n1, double n2) 38 | { 39 | if(n2==0) 40 | { 41 | Console.WriteLine("ALERT: Division by zero is invalid!"); 42 | } 43 | else 44 | { 45 | Console.WriteLine("The Result is:{0}\n", n1 / n2); 46 | } 47 | } 48 | static void Main(string[] args) 49 | { 50 | //define main commands you want 51 | string cmd = String.Empty; 52 | do 53 | { 54 | Console.WriteLine("This is an arithmetic claculator for console commands"); 55 | Console.WriteLine("Type help to get the list of commands available"); 56 | Console.WriteLine("To exit at any time type exit command"); 57 | //default command symbol 58 | Console.Write(":>"); 59 | //make input as case insensitive 60 | cmd = Console.ReadLine().ToString().ToLower(); 61 | switch(cmd) 62 | { 63 | //help command case here 64 | case "help": 65 | StringBuilder sb = new StringBuilder(); 66 | sb.Append("start:Starts Calculator\n"); 67 | sb.Append("exit:Exits Calculator\n"); 68 | sb.Append("cls:Clears the Screen\n"); 69 | Console.WriteLine(sb.ToString()); 70 | break; 71 | //exit command case here 72 | case "exit": 73 | break; 74 | //start command case here 75 | case "start": 76 | { 77 | //take two inputs for the arithmetic operations 78 | Console.WriteLine("Enter two numbers:"); 79 | string n1 = Console.ReadLine(); 80 | string n2 = Console.ReadLine(); 81 | //define two double variables for the inputs 82 | double num1=0.0, num2=0.0; 83 | //Filter the input for double data type here 84 | try 85 | { 86 | if ((InputValidator(n1) == true) && (InputValidator(n2) == true)) 87 | { 88 | Console.WriteLine("Enter only numbers here!"); 89 | } 90 | else 91 | { 92 | //convert the input into a double data type 93 | num1 = double.Parse(n1); 94 | num2 = double.Parse(n2); 95 | StringBuilder sb1 = new StringBuilder(); 96 | //arithmetic commands 97 | sb1.Append("add:Addition\n"); 98 | sb1.Append("sub:Subtraction\n"); 99 | sb1.Append("mult:Multiplication\n"); 100 | sb1.Append("div:Division"); 101 | Console.WriteLine("Type your commands here:\n" + sb1.ToString()); 102 | Console.Write(">:"); 103 | string choice = Console.ReadLine().ToString().ToLower(); 104 | switch (choice) 105 | { 106 | case "add": 107 | add(num1, num2); 108 | break; 109 | case "sub": 110 | sub(num1, num2); 111 | break; 112 | case "mult": 113 | mult(num1, num2); 114 | break; 115 | case "div": 116 | div(num1, num2); 117 | break; 118 | default: 119 | //default command error message 120 | Console.WriteLine("Bad Command"); 121 | break; 122 | } 123 | } 124 | 125 | } 126 | catch 127 | { 128 | //arithmetic operation failure message 129 | Console.WriteLine("ALERT: Something isn't right!"); 130 | } 131 | 132 | break; 133 | } 134 | //clear screen command case 135 | case "cls": 136 | Console.Clear(); 137 | break; 138 | default: 139 | //default wrong command message 140 | Console.WriteLine("Bad Command"); 141 | break; 142 | 143 | } 144 | 145 | } 146 | //run the screen till exit command typed 147 | while (cmd.ToLower()!="exit"); 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /Python/currency.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import sys, os, os.path, urllib2, re, cookielib, time, datetime, locale 3 | 4 | file = 'conv_rates.txt' #file containing the exchange rates 5 | 6 | locale.setlocale( locale.LC_ALL, '' ) 7 | 8 | def check_file(file): 9 | #check that the file exists and it's not empty 10 | if os.path.exists(file) == False or os.stat(file).st_size == 0: 11 | grab_web_rates() 12 | 13 | #check that the file is no more than 24 hours old 14 | if time.time() - os.path.getmtime(file) > 86400: #file older than 24 hours 15 | #grab the currency exchange data form the internet 16 | grab_web_rates() 17 | else: #file is up to date 18 | return create_exchange_dict() 19 | 20 | def create_exchange_dict(): 21 | exchange_rates_dict = {} 22 | conversion_rates = open (file, 'r') #open file read only 23 | 24 | for line in conversion_rates: 25 | exchange_rates_dict[line.split(",")[0]] = line.split(",")[1] 26 | 27 | conversion_rates.close() 28 | return exchange_rates_dict 29 | 30 | def grab_web_rates(): 31 | conversion_rates = open (file, 'w') 32 | web = urllib2.urlopen('http://www.x-rates.com/table/?from=USD') 33 | html = web.read() 34 | line = 1 35 | titles = re.findall(r' 36 | ', html) 37 | for title in titles: 38 | title = title.replace("amp;to=", "") 39 | title = title.replace("&", "-") 40 | title = title.replace("'>", ",") 41 | title = title.replace("", " ") 42 | title = title.replace(" ", "") 43 | title = title.rstrip() 44 | conversion_rates.write(title + ' \n') 45 | line += 1 46 | if line >= 23: 47 | break 48 | conversion_rates.close() 49 | 50 | def get_result(choice, amount): 51 | dict = create_exchange_dict() 52 | for exchange,rate in dict.items(): 53 | if exchange == choice: 54 | result = amount * float(rate) 55 | return rate, result 56 | break 57 | else: 58 | error = "Exchange not found! -get_result()- " 59 | 60 | def format_currency(value): 61 | return "{:,.2f}".format(value) 62 | 63 | def checkChoice(choice): 64 | if str.isdigit(choice): #check that the selection is a digit or exit 65 | return True 66 | else: 67 | os.system('clear') 68 | print "Thanks for using Currency Calculator! \n" 69 | exit() 70 | 71 | def main(): 72 | os.system('clear') 73 | print ''' 74 | Chose the Conversion: 75 | 1. US Dollar -> Euro 76 | 2. Euro -> US Dollar 77 | 3. US Dollar -> British Pound 78 | 4. British Pound -> US Dollar 79 | 5. US Dollar -> Canadian Dollar 80 | 6. Canadian Dollar -> US Dollar 81 | 7. US Dollar -> Chines Yuan 82 | 8. Chines Yuan -> US Dollar 83 | 9. US Dollar -> Peso Argentino 84 | 10. Peso Argentino -> US Dollar 85 | 0. Exit 86 | ''' 87 | choice = raw_input("\t") 88 | 89 | checkChoice(choice) 90 | choice = int(choice) 91 | 92 | #Exit script if the selection is not whithin the allowed range 93 | if choice == 0 or choice > 10: 94 | os.system('clear') 95 | print "Thanks for using Currency Calculator! \n" 96 | exit() 97 | 98 | while choice != 0: 99 | check_file(file) 100 | amount = raw_input("Amount: ") 101 | 102 | #Strips commas if found 103 | if ',' in amount: 104 | amount = ''.join(e for e in amount if e.isdigit() or e == '.') 105 | amount = float(amount) 106 | else: 107 | amount = float(amount) 108 | 109 | if choice == 1: #USD->Euro 110 | os.system('clear') 111 | choice = "USD-EUR" 112 | r = get_result(choice, amount) 113 | result = r[1] 114 | rate = r[0] 115 | e=u'\u20ac' #euro symbol 116 | amount = locale.currency( amount, grouping=True ) 117 | print "Your amount (USD): ", amount 118 | print "Converts to (EUR): ", e, format_currency(result) 119 | print "The Euro (EUR) -> US Dollar exchange rate is: ", rate 120 | break 121 | 122 | elif choice == 2: #EURO->USD 123 | os.system('clear') 124 | choice = "EUR-USD" 125 | r = get_result(choice, amount) 126 | result = r[1] 127 | rate = r[0] 128 | e=u'\u20ac' #euro symbol 129 | amount = format_currency(amount) 130 | print "Your amount (EUR): ", e, amount 131 | print "Converts to (USD): ", locale.currency(result, grouping=True) 132 | print "The US Dollar -> Euro (EUR) exchange rate is: ", rate 133 | break 134 | 135 | elif choice == 3: #GBP->USD 136 | choice = "USD-GBP" 137 | os.system('clear') 138 | r = get_result(choice, amount) 139 | result = r[1] 140 | rate = r[0] 141 | e = u'\xA3' #British Pound symbol 142 | amount = locale.currency( amount, grouping=True ) 143 | print "Your amount (USD): ", amount 144 | print "Converts to (GBP): ", e, format_currency(result) 145 | print "The US Dollar -> British Pound (GBP) exchange rate is: ", rate 146 | break 147 | 148 | elif choice == 4: #USD->GBP 149 | choice = "GBP-USD" 150 | os.system('clear') 151 | r = get_result(choice, amount) 152 | result = r[1] 153 | rate = r[0] 154 | e = u'\xA3' #British Pound symbol 155 | amount = format_currency(amount) 156 | print "Your amount (GBP): ", e, amount 157 | print "Converts to (USD): ", locale.currency(result, grouping=True ) 158 | print "The British Pound (GBP) -> US Dollar exchange rate is: ", rate 159 | break 160 | 161 | elif choice == 5: #CAD->USD 162 | choice = "USD-CAD" 163 | os.system('clear') 164 | r = get_result(choice, amount) 165 | result = r[1] 166 | rate = r[0] 167 | amount = locale.currency( amount, grouping=True ) 168 | result = locale.currency( result, grouping=True ) 169 | print "Your amount (USD): ", amount 170 | print "Converts to (CAD): ", result 171 | print "The US Dollar -> Canadian Dollar (CAD) exchange rate is: ", rate 172 | break 173 | 174 | elif choice == 6: #USD->CAD 175 | choice = "CAD-USD" 176 | os.system('clear') 177 | r = get_result(choice, amount) 178 | result = r[1] 179 | rate = r[0] 180 | amount = locale.currency( amount, grouping=True ) 181 | result = locale.currency( result, grouping=True ) 182 | print "Your amount (CAD): ", amount 183 | print "Converts to (USD): ", result 184 | print "The Canadian Dollar (CAD) -> US Dollar exchange rate is: ", rate 185 | break 186 | 187 | elif choice == 7: #USD->CNY 188 | choice = "USD-CNY" 189 | os.system('clear') 190 | r = get_result(choice, amount) 191 | result = r[1] 192 | rate = r[0] 193 | amount = locale.currency( amount, grouping=True ) 194 | print "Your amount (CNY): ", amount 195 | print "Converts to Yuan (USD): " , format_currency(result) 196 | print "The US Dollar -> Chinese Yuan (CNY) exchange rate is: ", rate 197 | break 198 | 199 | elif choice == 8: #CNY->USD 200 | choice = "CNY-USD" 201 | os.system('clear') 202 | r = get_result(choice, amount) 203 | result = r[1] 204 | rate = r[0] 205 | print "Your amount (CNY): ", format_currency(amount) 206 | print "Converts to Yuan (USD): " , locale.currency( result, grouping=True ) 207 | print "The Chinese Yuan (CNY) -> US Dollar exchange rate is: ", rate 208 | break 209 | 210 | elif choice == 9: #USD->ARS 211 | choice = "USD-ARS" 212 | os.system('clear') 213 | r = get_result(choice, amount) 214 | result = r[1] 215 | rate = r[0] 216 | amount = locale.currency( amount, grouping=True ) 217 | print "Your amount (USD): ", amount 218 | print "Converts in Peso Argentino (ARS): " , format_currency(result) 219 | print "The US Dollar -> Peso Argentino (ARS) exchange rate is: ", rate 220 | break 221 | 222 | elif choice == 10: #ARS->USD 223 | choice = "ARS-USD" 224 | os.system('clear') 225 | r = get_result(choice, amount) 226 | result = r[1] 227 | rate = r[0] 228 | print "Your amount (ARS): ", format_currency(amount) 229 | print "Converts to US Dollar (USD): " , locale.currency(result, grouping=True) 230 | print "The Peso Argentino (ARS) -> US Dollar exchange rate is: ", rate 231 | break 232 | 233 | elif choice > 10: 234 | exit() 235 | break 236 | 237 | #execution 238 | main() 239 | -------------------------------------------------------------------------------- /Java/Btree.java: -------------------------------------------------------------------------------- 1 | public class Btree { 2 | 3 | public Node root; 4 | 5 | Btree() { 6 | // new root 7 | root = new Node(); 8 | // assign the root node to be a isLeaf 9 | root.isLeaf = true; 10 | root.numberOfNodes = 0; 11 | // initial the key value in the root to -1 (null) 12 | root.key[0] = -1; 13 | } 14 | 15 | 16 | public void insert(int k) 17 | { 18 | 19 | Node r = root; 20 | 21 | if (r.numberOfNodes == 3) { 22 | // Create a new node s 23 | Node s = new Node(); 24 | // the new node s will become a new root node after root node r gets spilt 25 | root = s; 26 | s.numberOfNodes = 0; 27 | // the new root node is no longer a isLeaf 28 | s.isLeaf = false; 29 | s.children[0] = r; 30 | 31 | //Call the split method to split the node r because it is full 32 | splitChild(s, 1, r); 33 | //Call the insert in none full node method to insert the key k into the new node s 34 | insertNonfull(s, k); 35 | } // If the root r node is not full, just insert the key k into it by calling the insert in none full node method 36 | else { 37 | insertNonfull(r, k); 38 | } 39 | } 40 | 41 | 42 | public void insertNonfull(Node node, int value) { 43 | // Alocate the node 44 | int i = node.numberOfNodes; 45 | // if the node is a isLeaf, we insert the value into the node 46 | if (node.isLeaf) { 47 | while (i >= 1 && value < node.key[i - 1]) { 48 | node.key[i] = node.key[i - 1]; 49 | i--; 50 | } 51 | node.key[i] = value; 52 | node.numberOfNodes++; 53 | } 54 | else { 55 | while (i >= 1 && value < node.key[i - 1]) { 56 | i--; 57 | } 58 | i++; 59 | // if the node is full, split it. 60 | if (node.children[i - 1].numberOfNodes == 3) { 61 | // call the Split child method to split the node to two nodes 62 | splitChild(node, i, node.children[i - 1]); 63 | // Determine which of the two children is now the correct one to descend to. 64 | if (value > node.key[i - 1]) { 65 | i++; 66 | } 67 | } 68 | // Recursive Call 69 | insertNonfull(node.children[i - 1], value); 70 | } 71 | } 72 | 73 | public void splitChild(Node parentNode, int childIndex, Node newChild) { 74 | // Create a new node z, z will be the new child of node x 75 | Node z = new Node(); 76 | z.isLeaf = newChild.isLeaf; 77 | z.numberOfNodes = 1; // fix it to t-1 78 | z.key[0] = newChild.key[2]; 79 | 80 | // if node y is not a isLeaf, assign the largest t-1 keys and child to the node z. 81 | if (!newChild.isLeaf) { 82 | z.children[1] = newChild.children[3]; 83 | z.children[0] = newChild.children[2]; 84 | } 85 | newChild.numberOfNodes = 1; // fix it to t -1 86 | 87 | // Here we insert node z as a child of node x 88 | for (int j = parentNode.numberOfNodes + 1; j >= childIndex + 1; j--) { 89 | parentNode.children[j] = parentNode.children[j - 1]; 90 | parentNode.key[j - 1] = parentNode.key[j - 2]; 91 | } 92 | // assign the reference to the node z ( node z is a child of the node x) 93 | parentNode.children[childIndex] = z; 94 | parentNode.key[childIndex - 1] = newChild.key[1]; 95 | // increment 96 | parentNode.numberOfNodes++; 97 | } 98 | 99 | 100 | public boolean search(Node node, int value) { 101 | // initial i to be equal to 1 102 | int i = 1; 103 | 104 | while (i <= node.numberOfNodes && value > node.key[i - 1]) { 105 | //increment i 106 | i++; 107 | } 108 | if (i <= node.numberOfNodes && value == node.key[i - 1]) { 109 | // return true if the key k is found in the B Tree 110 | return true; 111 | } 112 | 113 | if (!node.isLeaf) { 114 | // recursive call to search in the subtree of the node x 115 | return search(node.children[i - 1], value); 116 | } 117 | return false; 118 | } 119 | 120 | 121 | public boolean search(int k) { 122 | // assign the node x to be the root and start search from the root 123 | Node x = root; 124 | // send the root x and the key k as an arguments to the the method search above 125 | return search(x, k); 126 | } 127 | 128 | public boolean delete(int k) { 129 | Node x = root; // getting the root node 130 | return delete(x, k); // calling the delete with the root node as starting point 131 | } 132 | 133 | 134 | public boolean delete(Node node, int value) { 135 | // look up for a key k that will be deleted 136 | int i = 1; 137 | //--- 138 | // find the smallest index i such that k<= x.keyi, or else set i to x.n ++ 139 | while (i <= node.numberOfNodes && value > node.key[i - 1]) { 140 | //increment i 141 | i++; 142 | } 143 | /* if the x node is an internal node, terminate the search unsuccessful or 144 | * recurse to search the appropriate subtree of node x. 145 | */ 146 | // if the node is a is Leaf 147 | if (node.isLeaf) { 148 | // recursive call to search in the subtree of the node x 149 | // check if the key k is found 150 | if (i <= node.numberOfNodes && value == node.key[i - 1]) { 151 | // return true if the key k is found in the B Tree 152 | node.key[i - 1] = 0; 153 | // Deleting and sifting 154 | for(int j = i - 1; j < node.numberOfNodes - 1; j++){ 155 | node.key[j] = node.key[j+1]; 156 | if(j+1 == node.numberOfNodes - 1) 157 | node.numberOfNodes--; 158 | } 159 | return true; 160 | } 161 | } else { 162 | return delete(node.children[i - 1], value); 163 | } 164 | // return false if the key k is not found in the B Tree 165 | return false; 166 | } 167 | 168 | /** 169 | * To print the B-Tree 170 | */ 171 | public void print() { 172 | // Call the printBtree Method to print the B-Tree 173 | printBtree(root, ""); 174 | } 175 | 176 | /** 177 | * This Method is to print the B-Tree 178 | * @param node the node to be printed 179 | * @param indent the wanted indent. 180 | */ 181 | public void printBtree(Node node, String indent) { 182 | // if the node is null print "The B-Tree is Empty" 183 | if (node == null) { 184 | System.out.println(indent + "The B-Tree is Empty"); 185 | } else { 186 | System.out.println(indent + " "); 187 | 188 | // declare a string variable 189 | String childIndent = indent + "\t"; 190 | 191 | // for loop to print the B-Tree, recursively print the B-Tree Strucure 192 | for (int i = node.numberOfNodes-1; i >= 0; i--) { 193 | if (!node.isLeaf) // Recursive Call 194 | { 195 | printBtree(node.children[i], childIndent); 196 | } 197 | // print the keys 198 | if(node.key[i] > 0) 199 | System.out.println(childIndent + node.key[i]); 200 | } 201 | if (!node.isLeaf) // Recirsive Call 202 | { 203 | printBtree(node.children[node.numberOfNodes], childIndent); 204 | } 205 | } 206 | } 207 | } --------------------------------------------------------------------------------