diff --git a/Algorithms b/Algorithms new file mode 160000 index 000000000..e6a075705 --- /dev/null +++ b/Algorithms @@ -0,0 +1 @@ +Subproject commit e6a0757056d79285b1f36e72c7ce9a7b411c13a9 diff --git a/Array/largest_sum_contiguous_subarray.py b/Array/largest_sum_contiguous_subarray.py new file mode 100644 index 000000000..797cb8d5d --- /dev/null +++ b/Array/largest_sum_contiguous_subarray.py @@ -0,0 +1,13 @@ +def largest_sum_contiguous_subarray(arr): + max_now = 0 + max_next = 0 + for i in arr: + max_next += i + max_now = max(max_next, max_now) + max_next = max(0, max_next) + return max_now + + + +arr = list(map(int,input().split())) +print('Maximum contiguous sum is', largest_sum_contiguous_subarray(arr)) diff --git a/Random Number/Guess-The-Number.java b/Random Number/Guess-The-Number.java new file mode 100644 index 000000000..f25dbde63 --- /dev/null +++ b/Random Number/Guess-The-Number.java @@ -0,0 +1,35 @@ +import java.util.*; + +public class Program +{ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + Random rand = new Random(); + + int number = rand.nextInt(100); + + System.out.println("Enter A number between 1 to 100"); + int input = sc.nextInt(); + int count=1; + while(input!=number){ + if(input>number) + System.out.println("Number Guess by You is Higher"); + else + System.out.println("Number Guess by You is Smaller"); + System.out.println("1.Continue\n2.Exit"); + int choice=sc.nextInt(); + switch(choice){ + case 1: + input=sc.nextInt(); + break; + case 2: + System.exit(0); + } + count++; + } + + System.out.println("Congratulation You Guess Number Correctly in "+count); + + } +} diff --git a/Random Number/random_walk.py b/Random Number/random_walk.py new file mode 100644 index 000000000..ad3583e89 --- /dev/null +++ b/Random Number/random_walk.py @@ -0,0 +1,33 @@ + +import numpy as np +import matplotlib.pyplot as plt + +n = int(input('Enter number of random step u want to walk: ')) +print("") + +np.random.seed(123) +random_walk = [0] + +for x in range(n) : + # Set step: last element in random_walk + step = random_walk[-1] + # Roll the dice + dice = np.random.randint(1,7) + + # Determine next step + if dice <= 2: + step = max(0,step - 1) + elif dice <= 5: + step = step + 1 + else: + step = step + np.random.randint(1,7) + + # append next_step to random_walk + random_walk.append(step) + + +print(random_walk) + + +plt.plot(random_walk) +plt.show() \ No newline at end of file