Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random Number #1620

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Algorithms
Submodule Algorithms added at e6a075
13 changes: 13 additions & 0 deletions Array/largest_sum_contiguous_subarray.py
Original file line number Diff line number Diff line change
@@ -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))
35 changes: 35 additions & 0 deletions Random Number/Guess-The-Number.java
Original file line number Diff line number Diff line change
@@ -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);

}
}
33 changes: 33 additions & 0 deletions Random Number/random_walk.py
Original file line number Diff line number Diff line change
@@ -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()