From 3621e1d748010cc7985e6c762839c77ec80ff932 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 30 Oct 2020 22:31:58 +0530 Subject: [PATCH 1/3] Random Number --- Random Number/Guess-The-Number.java | 35 +++++++++++++++++++++++++++++ Random Number/random_walk.py | 33 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 Random Number/Guess-The-Number.java create mode 100644 Random Number/random_walk.py 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 From 4b97f2a746d74424045d5a042f543f972e58a806 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 31 Oct 2020 07:43:34 +0530 Subject: [PATCH 2/3] Array --- Array/largest_sum_contiguous_subarray.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Array/largest_sum_contiguous_subarray.py 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)) From b627736e7e5938656b912804939d9f1599a37e95 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 31 Oct 2020 08:12:42 +0530 Subject: [PATCH 3/3] Array --- Algorithms | 1 + 1 file changed, 1 insertion(+) create mode 160000 Algorithms diff --git a/Algorithms b/Algorithms new file mode 160000 index 000000000..e6a075705 --- /dev/null +++ b/Algorithms @@ -0,0 +1 @@ +Subproject commit e6a0757056d79285b1f36e72c7ce9a7b411c13a9