This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def mainfunction(): | |
while True: | |
rnum = random.randrange(1,4) | |
cpuschoice = numtochoice(rnum) | |
userscoice = input("Choose between stone, paper and scissor\n") | |
print('Cpu has choosen : ', cpuschoice) | |
print(decision(userscoice.lower(), cpuschoice)) | |
def numtochoice(num): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
cpunum = random.randrange(1,9) | |
usernum = 0 | |
count = 0 | |
print('guess a number between 1 and 9') | |
while True: | |
usernum = input() | |
count += 1 | |
if usernum== 'exit': | |
break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
a= random.sample(range(1,30), 7) | |
b= random.sample(range(1,30), 10) | |
result1= [] | |
result2 = [] | |
result3 = [] | |
for element in a: | |
if element in b: | |
result1.append(element) | |
print(result1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
userinput = int(input("Enter the number to check prime\n")) | |
a = [] | |
if userinput == 1: | |
print("One is not a prime nor a composite") | |
else: | |
if userinput == 2 or userinput%2 != 0: | |
for x in range(1,userinput): | |
if userinput%x==0 : | |
a.append(x) | |
if len(a)==1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def inserlist(givenlist): | |
first, *middle, last = givenlist | |
newlist = [first, last] | |
return newlist | |
list = [12,45,78,45,96,67,81,39] | |
print("List to be clipped is",list) | |
print("First and the last element of clip are",inserlist(list)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
let food = [ | |
{type: 'beverage', name: 'tea'}, | |
{type: 'veg', name: 'aloo paratha'}, | |
{type: 'non-veg', name: 'biryani'}, | |
{type: 'non-veg', name: 'butter chicken'} | |
]; | |
const filterFunction = (string) => (item) => item.type === string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Interview question of the week by Cassidy Williams's Newsletter | |
// This week's question courtesy of Louis: | |
// Write a function that takes the name of a day (e.g "Monday", "Tuesday") | |
// and an integer offset, and returns the name of the day which would be the original + offset. | |
// Extra credit: do it in 1 line! | |
// Example: | |
// > dayOffset("Wednesday", 4) | |
// > "Sunday" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stair(n){ | |
if(n === 1){ return 1; } | |
if(n === 2){ return 2; } | |
return memoizedStair(n-1) + memoizedStair(n-2); | |
} | |
function memoize(fn){ | |
const cache = {}; | |
return function(...args){ | |
if(cache[args]){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cutRod(n, prices){ | |
if(n === 0){ return 0; } | |
let maxRevenue = -1; | |
for( let i = 0; i < n; i++){ | |
maxRevenue = Math.max(maxRevenue, prices[n- i - 1] + memoizedCutRod(i, prices)); | |
} | |
return maxRevenue; | |
} | |
function memoize(fn){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Iterate through user object and flatter in one object. | |
//append _ on every level | |
var user = { | |
name: "Shad", | |
address: { | |
personal: { | |
city: "Varanasi", | |
area: "Chauhatta", | |
}, | |
office: { |
OlderNewer