blob_id stringlengths 40 40 | repo_name stringlengths 5 127 | path stringlengths 2 523 | length_bytes int64 22 545k | score float64 3.5 5.34 | int_score int64 4 5 | text stringlengths 22 545k |
|---|---|---|---|---|---|---|
1a7343416b87e66d3f5be48de83eebdf0187f4ef | virgax7/ProjectEuler | /src/questions-1-20/q4-p.py | 346 | 4 | 4 | # A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
#
# Find the largest palindrome made from the product of two 3-digit numbers.
import numpy
print(numpy.max([i * j if str(i * j) == str(i * j)[::-1] else 0 for i in range(100, 999) for... |
a39688d3f3e53ab342c061696e825549f84ea6f5 | juanengml/web-scraping-python | /usando beautifulsoup/tratando_erros.py | 1,070 | 3.734375 | 4 | ### Com urllib
from urllib.request import urlopen
from urllib.error import HTTPError, URLError
"""
html = urlopen("http://www.wingsec.com")
print(f"Html 1: {html}")
try:
html = urlopen("http://www.wingsec.com/erro")
print(f"Html 2: {html}")
except HTTPError as erro:
print(erro)
html = urlopen("http://www.... |
1f97de5de1f342d9dcdeb4267a0a257b272f761f | suyinlong/vis.world-food-facts | /main/query.py | 645 | 3.640625 | 4 | # -*- coding: utf-8 -*-
# @Author: Yinlong Su
# @Date: 2016-05-11 19:11:05
# @Last Modified by: Yinlong Su
# @Last Modified time: 2016-05-12 18:47:29
import pandas
countryColumnName = 'countries_en'
categoryColumnName = 'main_category_en'
def dfQuery(df, country, category):
if country == 'all':
q1 = ... |
58245ae6cc3d9ec927fe6c2ac2becfa4e24742e7 | CesarVerissimo/Atividade-1 | /Exercicio 1.py | 82 | 3.875 | 4 | num = int(input("Digite um numero inteiro:"))
print("O resultado é:", num * 2)
|
79448c16194dcb8811d6e26b8e652511cacb907a | mdk44/AdventOfCode2019 | /Day1/Day1.py | 456 | 3.671875 | 4 | input_file = 'Day1\\Input.csv'
text_file = open(input_file)
lines = text_file.read().split()
# Part 1
sum_p1 = 0
for line in lines:
cur_wt = int(int(line) / 3) - 2
sum_p1 += cur_wt
print("Sum for Part 1: " + str(sum_p1))
sum_p2 = 0
for line in lines:
cur_wt = int(line)
while cur_wt > 0... |
36a5612ef360eeb868da742bc9f29f535cb3fb84 | saparia-data/data_structure | /geeksforgeeks/maths/2_celcius_to_fahrenheit.py | 852 | 4.5 | 4 | """
Given a temperature in celsius C. You need to convert the given temperature to Fahrenheit.
Input Format:
The first line of input contains T, denoting number of testcases. Each testcase contains single integer C denoting the temperature in celsius.
Output Format:
For each testcase, in a new line, output the temper... |
795bc9954ddcd5e52ad3477bf197c5bedd9a9650 | saparia-data/data_structure | /geeksforgeeks/linked_list/segregate_even_and_odd_nodes_in_linked_list_difficullt.py | 2,808 | 4.15625 | 4 | '''
Given a Linked List of integers, write a function to modify the linked list such that all even numbers appear before all the odd numbers in the modified linked list.
Also, keep the order of even and odd numbers same.
https://www.geeksforgeeks.org/segregate-even-and-odd-elements-in-a-linked-list/
'''
class Node: ... |
17d7ca663bf8697b79bd7824a49e561839818cf3 | saparia-data/data_structure | /pepcoding/dynamic_programming/4_climb_stairs_with_minimum_moves.py | 1,375 | 4.15625 | 4 | '''
1. You are given a number n, representing the number of stairs in a staircase.
2. You are on the 0th step and are required to climb to the top.
3. You are given n numbers, where ith element's value represents - till how far from the step you
could jump to in a single move. You can of-course fewer number of ste... |
b9de1e2c1d33f5c66f0e9f97de66306b62190d54 | saparia-data/data_structure | /geeksforgeeks/backtracking/2_black_and_white_knight_problem.py | 1,500 | 3.671875 | 4 | '''
Given the chessboard dimensions. Find out the number of ways we can place a black and a white Knight on this chessboard
such that they cannot attack each other.
Note:
The knights have to be placed on different squares.
A knight can move two squares horizontally and one square vertically (L shaped), or two square... |
3011d256bbe671b269e85202b96ec565210796de | saparia-data/data_structure | /geeksforgeeks/linked_list/14_Find_length_of_Loop.py | 2,466 | 3.90625 | 4 | '''
Given a linked list of size N. The task is to complete the function countNodesinLoop() that checks whether a given Linked List contains a loop or not
and if the loop is present then return the count of nodes in a loop or else return 0.
Input:
The first line of input contains the number of testcases T. For each te... |
fea46e295115747dfcc38e182eb865603b501e74 | saparia-data/data_structure | /pepcoding/recursion/1_tower_of_hanoi.py | 961 | 4.15625 | 4 | '''
1. There are 3 towers. Tower 1 has n disks, where n is a positive number. Tower 2 and 3 are empty.
2. The disks are increasingly placed in terms of size such that the smallest disk is on top and largest disk is at bottom.
3. You are required to
3.1. Print the instructions to move the disks.
3.2. from tower... |
dde3c99f5a7574ec1dc9f438a46027de7a50000e | saparia-data/data_structure | /geeksforgeeks/stack/previous_greater_element.py | 550 | 3.875 | 4 | '''
https://www.geeksforgeeks.org/previous-greater-element/
'''
def prevGreater(arr, n):
s = list()
s.append(arr[0])
output = []
output.append(-1)
for i in range(1, n):
while(len(s) > 0 and s[-1] < arr[i]):
s.pop()
if(len(s) == 0):
... |
60937f08311c74e6773fa09eaec056097efb9496 | saparia-data/data_structure | /pepcoding/generic_tree/17_is_generic_tree_symmetric.py | 1,776 | 4.1875 | 4 | '''
The function is expected to check if the tree is symmetric, if so return true otherwise return false.
For knowing symmetricity think of face and hand. Face is symmetric while palm is not.
Note: Symmetric trees are mirror image of itself.
Sample Input:
20
10 20 50 -1 60 -1 -1 30 70 -1 80 -1 90 -1 -1 40 100 -1 1... |
37da539040983c8b83b2c7893a416c805721f342 | saparia-data/data_structure | /geeksforgeeks/stack/10_Infix_to_Postfix.py | 5,115 | 4.09375 | 4 | '''
Given an infix expression in the form of string str. Conver this infix expression to postfix expression.
Infix expression: The expression of the form a op b. When an operator is in-between every pair of operands.
Postfix expression: The expression of the form a b op. When an operator is followed for every pair of ... |
009cdd3d6e7ce71f4be5158d184b29f1a731d1f3 | saparia-data/data_structure | /geeksforgeeks/array/12_Frequencies_of_Limited_Range_Array_Elements.py | 2,199 | 4.03125 | 4 | '''
Given an array A[] of N positive integers which can contain integers from 1 to N where elements can be repeated or can be absent from the array.
Your task is to count frequency of all elements from 1 to N.
Note: Expected time complexity is O(n) with O(1) extra space.
Input Format:
First line of input contains an... |
8ed22c85e24b7aab43c3f9c54c90ee523a8e3964 | saparia-data/data_structure | /geeksforgeeks/searching/16_allocate_minimum_number_of_pages_pending.py | 3,056 | 3.578125 | 4 | '''
You are given N number of books. Every ith book has Pi number of pages.
You have to allocate books to M number of students. There can be many ways or permutations to do so.
In each permutation one of the M students will be allocated the maximum number of pages.
Out of all these permutations, the task is to fi... |
008b19ff7efc7fc9be540903c086a792aed6c0d2 | saparia-data/data_structure | /geeksforgeeks/maths/7_prime_or_not.py | 1,297 | 4.34375 | 4 | '''
For a given number N check if it is prime or not. A prime number is a number which is only divisible by 1 and itself.
Input:
First line contains an integer, the number of test cases 'T'. T testcases follow. Each test case should contain a positive integer N.
Output:
For each testcase, in a new line, print "Yes" i... |
171bff73e42b41ff70a27b63c463d756d24c7de1 | saparia-data/data_structure | /geeksforgeeks/recursion/5_josephus.py | 1,763 | 3.578125 | 4 | '''
Given the total number of persons n and a number k which indicates that k-1 persons are skipped and kth person is killed in circle in a fixed direction.
The task is to choose the safe place in the circle so that when you perform these operations starting from 1st place in the circle,
you are the last one remainin... |
003e8f921c2b9cf87e68ea9dde217330acd8e46a | saparia-data/data_structure | /geeksforgeeks/dynamic_programming/7_longest_increasing_subsequence_nlogn.py | 1,736 | 4.09375 | 4 | '''
Given an array of integers, find the length of the longest (strictly) increasing subsequence from the given array.
Example 1:
Input:
N = 16
A[]={0,8,4,12,2,10,6,14,1,9,5
13,3,11,7,15}
Output: 6
Explanation:Longest increasing subsequence
0 2 6 9 13 15, which has length 6
https://www.geeksforgeeks.org/construc... |
a7e3d0f8433ab03d424802b927e4baa313fc8acd | saparia-data/data_structure | /pepcoding/recursion/4_max_in_array.py | 303 | 4.0625 | 4 | '''
print max value in array
'''
def arrayMax(arr, idx):
if(idx == len(arr) - 1):
return arr[idx]
element = arrayMax(arr, idx+1)
if(element > arr[idx]):
maxx = element
else:
maxx = arr[idx]
return maxx
print(arrayMax([20,10,5,40,45], 0)) |
9296a6e49b6a82af726953627b656f371e6a9996 | saparia-data/data_structure | /geeksforgeeks/tree/28_Maximum_difference_between_node_and_its_ancestor.py | 1,570 | 3.96875 | 4 | '''
Given a Binary Tree, you need to find the maximum value which you can get by subtracting the value of node B from the value of node A,
where A and B are two nodes of the binary tree and A is an ancestor of B.
Input:
S = 5 2 1
Output: 4
Explanation:
5
/ \
2 1
The maximum difference we can get... |
3fb0fefa594130bd865c342d60d0f7ff34127f7f | saparia-data/data_structure | /geeksforgeeks/linked_list/4_Insert_in_Middle_of_Linked_List.py | 1,343 | 4.15625 | 4 | '''
Given a linked list of size N and a key. The task is to insert the key in the middle of the linked list.
Input:
The first line of input contains the number of test cases T. For each test case,
the first line contains the length of linked list N
and the next line contains N elements to be inserted into the linked... |
743ac63814f696ebb6add013c50dcae6b51b27ca | saparia-data/data_structure | /geeksforgeeks/stack/16_Maximum_of_minimum_for_every_window_size_pending.py | 1,983 | 3.578125 | 4 | '''
Given an integer array. The task is to find the maximum of the minimum of every window size in the array.
Note: Window size varies from 1 to the size of the Array.
Input:
The first line contains an integer T denoting the total number of test cases.
In each test cases, the first line contains an integer N denoting... |
296acd0cb1655e3fd6d57e80b9bd72529ffb4ecc | saparia-data/data_structure | /geeksforgeeks/matrix/8_Boundary_traversal_matrix.py | 2,384 | 4.34375 | 4 | '''
You are given a matrix A of dimensions n1 x m1.
The task is to perform boundary traversal on the matrix in clockwise manner.
Input:
The first line of input contains T denoting the number of testcases. T testcases follow.
Each testcase two lines of input. The first line contains dimensions of the matrix A, n1 and... |
789288e7c8987df76436b463f7e8fa6f2d9b1a8a | saparia-data/data_structure | /geeksforgeeks/tree/6_height_of_binary_tree.py | 698 | 4.125 | 4 | '''
Hint:
1. If tree is empty then return 0
2. Else
(a) Get the max depth of left subtree recursively i.e.,
call maxDepth( tree->left-subtree)
(a) Get the max depth of right subtree recursively i.e.,
call maxDepth( tree->right-subtree)
(c) Get the max of max depths of left and ri... |
9ebec7bb316594e349c8b1e8c7c4979527a4bf9a | saparia-data/data_structure | /geeksforgeeks/heap/10_K_Most_occurring_elements.py | 1,709 | 4.0625 | 4 | '''
Given an array arr[] of N integers in which elements may be repeating several times.
Also, a positive number K is given and the task is to find sum of total frequencies of K most occurring elements
Note: The value of K is guaranteed to be less than or equal to the number of distinct elements in arr.
Example 1:
I... |
40c39d4c7248ba1f414f02c088c36a907fb81b1a | saparia-data/data_structure | /geeksforgeeks/binary_search_tree/10_Find_pair_with_given_sum_in_BST.py | 1,946 | 3.84375 | 4 | '''
Given a BST and a number X. The task is to check if any pair exists in BST or not whose sum is equal to X.
Example 1:
Input:
8
/ \
5 9
/ \
1 3
X = 4
Output: 1
Explanation: For the given input, there
exist a pair whose sum is, i.e, (3,1).
https://www.youtube.com/watch?v=ouuGHu9Sjhg
Meth... |
770ac8812cac09b77d0990edacc7fed78c612480 | saparia-data/data_structure | /geeksforgeeks/maths/1_absolute_value_solved.py | 1,062 | 4.375 | 4 | '''
You are given an interger I. You need to print the absolute value of the interger I.
Input Format:
The first line of input contains T, denoting number of testcases. Each testcase contains single integer I which may be positive or negative.
Output Format:
For each testcase, in a new line, output the absolute value... |
aa8adb974c814ed9d5bbfc2029d50c3038f9708d | saparia-data/data_structure | /pepcoding/dynamic_programming/18_paint_house_many_colours_difficult.py | 3,028 | 3.6875 | 4 | '''
1. You are given a number n and a number k separated by a space, representing the number of houses and number of colors.
2. In the next n rows, you are given k space separated numbers representing the cost of painting nth house with one of the k colors.
3. You are required to calculate and print the minimum cost of... |
960c05ab5624625320bf46049e7cfc1cca1e8cfa | saparia-data/data_structure | /geeksforgeeks/searching/3_count_1_in_binary_array.py | 1,905 | 3.890625 | 4 | '''
Given a binary sorted non-increasing array arr of size N. You need to print the count of 1's in the binary array.
Input:
The input line contains T, denotes the number of test cases. Each input contains two lines.
The first line contains N(size of binary array).
The second line contains N elements of binary array... |
8134dad77481dd836328436a5f9720fe2576e723 | saparia-data/data_structure | /geeksforgeeks/linked_list/12b_reverse_linked_list_recursively.py | 1,058 | 4.09375 | 4 | '''
https://www.youtube.com/watch?v=MRe3UsRadKw
'''
class Node:
def __init__(self,data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def isEmpty(self):
return self.head == None
def add(self, data):
... |
35030f181df15a7fb1ad550279aadc98a6baf954 | saparia-data/data_structure | /geeksforgeeks/sorting/11_Counting_Sort.py | 1,265 | 4.25 | 4 | '''
Given a string S consisting of lowercase latin letters, arrange all its letters in lexographical order using Counting Sort.
Input:
The first line of the input contains T denoting number of testcases.Then T test cases follow. Each testcase contains positive integer N denoting the length of string.The last line of i... |
7e46d0a4e86ad7d64eb3807027739996c4b768af | saparia-data/data_structure | /pepcoding/generic_tree/3_maximum_in_generic_tree.py | 1,140 | 3.53125 | 4 | '''
find max value node in tree.
Sample Input:
12
10 20 -1 30 50 -1 60 -1 -1 40 -1 -1
Sample Output:
60
https://www.youtube.com/watch?v=eJnf0QBg64g&list=PL-Jc9J83PIiEmjuIVDrwR9h5i9TT2CEU_&index=7
'''
import sys
class Node:
def __init__(self):
self.data = None
self.children = []
def create... |
351a0ce356700aee8616a5e2776bbbffb36f45f9 | saparia-data/data_structure | /geeksforgeeks/queue/8_Circular_tour_difficult.py | 2,888 | 4.03125 | 4 | '''
Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting... |
599e5ddf7cd81169ce468da8f0eb1f1fbca31b45 | saparia-data/data_structure | /geeksforgeeks/sorting/7_Intersection_of_two_sorted_arrays.py | 1,982 | 4.0625 | 4 | '''
Given two sorted arrays arr1[] and arr2[] of sizes N and M respectively. The task is to find intersection of the two arrays.
Intersection of two arrays contains the elements common to both the arrays. The intersection should not count duplicate elements.
Input:
First line of input contains number of testcases T. F... |
ef815f8b348870fd51409da07533789451af6739 | saparia-data/data_structure | /geeksforgeeks/heap/build_heap_operation.py | 1,663 | 4.03125 | 4 | '''
https://www.geeksforgeeks.org/building-heap-from-array/
'''
def heapify(arr, n, i):
largest = i; # Initialize largest as root
l = 2 * i + 1; # left = 2*i + 1
r = 2 * i + 2; # right = 2*i + 2
# If left child is larger than root
if l < n and arr[l] > arr[largest]:
largest = l;... |
185c7bcb7e9aeb0ac6290390caa76284f6d71000 | saparia-data/data_structure | /geeksforgeeks/tree/15_Determine_if_Two_Trees_are_Identical.py | 360 | 3.734375 | 4 | '''
Given two binary trees, the task is to find if both of them are identical or not.
'''
def areIdentical(root1, root2):
if(root1 is None and root2 is None):
return 1
if(root1 is not None and root2 is not None):
return root1.data == root2.data and areIdentical(root1.left, root2.left) an... |
d476ee8753b489e9a160984ca1a71e49eed86f2d | saparia-data/data_structure | /geeksforgeeks/array/3_majority_in_array_solved.py | 2,439 | 4.40625 | 4 | '''
We hope you are familiar with using counter variables. Counting allows us to find how may times a certain element appears in an array or list.
You are given an array arr[] of size N. You are also given two elements x and y. Now, you need to tell which element (x or y) appears most in the array.
In other words, pri... |
9c553830eaf99a3ac9b33a957bc3fb37e3496e40 | saparia-data/data_structure | /geeksforgeeks/strings/22_rabin_karp_pattern_searching.py | 2,361 | 4.0625 | 4 | '''
Given a string S and a pattern P of lowercase characters. The task is to check if the pattern is present in string or not.
Input:
The first line of input contains the number of test cases T. For each testcase,
the first line of input contains string S and the next line contains pattern P.
Output:
For each testca... |
9e7260719eb9be37d66376e841158a861d4e465f | saparia-data/data_structure | /geeksforgeeks/graph/14_Distance_of_nearest_cell_having_1.py | 1,905 | 3.921875 | 4 | '''
Given a binary matrix. Find the distance of nearest 1 in the matrix for each cell.
You don't need to read input or print anything. Your task is to complete the function nearest() which takes the matrix (mat)
and its dimensions (N and M) as inputs and returns a matrix of same dimensions
where the value at index (... |
707f0c89a268dae828848106fc4e23a093981d1c | saparia-data/data_structure | /geeksforgeeks/linked_list/24_Intersection_Point_in_Y_Shapped_Linked_Lists.py | 2,922 | 3.9375 | 4 | '''
Given two singly linked lists of size N and M, write a program to get the point where two linked lists intersect each other.
Note: Expected time complexity is O(m + n) where m and n are lengths of two linked lists.
Input:
First line of input is the number of test cases T. Every test case has four lines. First lin... |
7f203877bf532440e3ca948eb7a28006d9c4fc61 | saparia-data/data_structure | /geeksforgeeks/tree/25_Tree_from_Postorder_and_Inorder.py | 2,069 | 4 | 4 | '''
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively.
The task is to construct the binary tree from these traversals.
For example, if given inorder and postorder traversals are {4, 8, 2, 5, 1, 6, 3, 7} and {8, 4, 5, 2, 6, 7, 3, 1} respectively,
then your function sho... |
23e5feeb0c8108706e9f83704727c6b3d9e29e51 | saparia-data/data_structure | /pepcoding/dynamic_programming/22_friends_pairing.py | 854 | 3.53125 | 4 | '''
1. You are given a number n, representing the number of friends.
2. Each friend can stay single or pair up with any of it's friends.
3. You are required to print the number of ways in which these friends can stay single or pair up.
E.g.
1 person can stay single or pair up in 1 way.
2 people can stay singles or pai... |
8f2e60355dfe700cfde7b30b569d431ce959b7e5 | saparia-data/data_structure | /geeksforgeeks/strings/6_check_if_string_is_rotated_by_two_places.py | 1,986 | 4.21875 | 4 | '''
Given two strings a and b. The task is to find if the string 'b' can be obtained by rotating another string 'a' by exactly 2 places.
Input:
The first line of input contains an integer T denoting the number of test cases.
Then T test cases follow. In the next two lines are two string a and b respectively.
Output:
... |
c3e3048b0f974bc5d59ff8bd93919977fcb979bd | saparia-data/data_structure | /pepcoding/recursion/2_print_array.py | 259 | 3.921875 | 4 | '''
You are required to print the elements of array from beginning to end each in a separate line.
'''
def printArray(arr, idx):
if(idx == len(arr)):
return
print(arr[idx])
printArray(arr, idx+1)
printArray([1,2,3,4,5], 0) |
85a96d3d3a59b18d3dc560d746ec03f06d40fefe | saparia-data/data_structure | /geeksforgeeks/sorting/16_Merge_Without_Extra_Space_difficult.py | 2,148 | 3.921875 | 4 | '''
Given two sorted arrays arr1[] and arr2[] in non-decreasing order with size n and m. The task is to merge the two sorted arrays in place,
i. e., we need to consider all n + m elements in sorted order,
then we need to put first n elements of these sorted in first array and remaining m elements in second array.
Note... |
b60ea01204ed5587e18a1f920375fa2d8038d5a4 | saparia-data/data_structure | /geeksforgeeks/hashing/9_pair_in_array_exist_for_given_sum.py | 2,131 | 3.765625 | 4 | '''
You are given an array A (distinct integers) of size N, and you are also given a sum.
You need to find if two numbers in A exists that have sum equal to the given sum.
Input:
The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains three lines of input.
The ... |
ee35bfec4f0710473a627a5c1c851df9fc18ef5f | saparia-data/data_structure | /geeksforgeeks/sorting/10_Three_way_partitioning.py | 3,121 | 3.625 | 4 | '''
Given an array A[] and a range [a, b]. The task is to partition the array around the range such that array is divided in three parts.
1) All elements smaller than a come first.
2) All elements in range a to b come next.
3) All elements greater than b appear in the end.
The individual elements of three sets can appe... |
f419a5c690314e07bde9a51929946805ea04fefe | saparia-data/data_structure | /geeksforgeeks/hashing/14_Winner_of_an_election.py | 2,177 | 4.0625 | 4 | '''
Given an array of names (consisting of lowercase characters) of candidates in an election. A candidate name in array represents a vote casted to the candidate. Print the name of candidate that received Max votes. If there is tie, print lexicographically smaller name.
Input:
The first line of the input contains a s... |
b6bf8024d4250adafec321751f4317591391a1c9 | saparia-data/data_structure | /geeksforgeeks/tree/26_Foldable_Binary_Tree.py | 1,007 | 4.4375 | 4 | '''
Given a binary tree, find out if the tree can be folded or not.
-A tree can be folded if left and right subtrees of the tree are structure wise mirror image of each other.
-An empty tree is considered as foldable.
Consider the below tree: It is foldable
10
/ \
7 15
\ /
9 1... |
b05134767f55b443af849edfa92df6ae5937491b | saparia-data/data_structure | /geeksforgeeks/matrix/11_Reversing_the _columns_Matrix.py | 1,919 | 4.40625 | 4 | '''
You are given a matrix A of dimensions n1 x m1.
The task is to reverse the columns(first column exchanged with last column and so on).
Input:
The first line of input contains T denoting the number of testcases. T testcases follow.
Each testcase two lines of input. The first line contains dimensions of the matrix... |
34c83a4969d111a66ba2b1729c57c9158641efe0 | saparia-data/data_structure | /geeksforgeeks/linked_list/11_Swap_Kth_nodes_from_ends.py | 4,598 | 4 | 4 | '''
Given a singly linked list of size N, and an integer K. You need to swap the Kth node from beginning and Kth node from the end in the linked list.
Note: You need to swap the nodes through the links and not changing the content of the nodes.
Input:
The first line of input contains the number of testcases T.
The f... |
7b229c1df825d5d3874f523533a4a9b258b4eb08 | saparia-data/data_structure | /geeksforgeeks/maths/6_n_term_geometric_progression.py | 1,250 | 4.03125 | 4 | '''
Given the first 2 terms A and B of a Geometric Series. The task is to find the Nth term of the series.
Input Format:
First line contains an integer, the number of test cases 'T'. T testcases follow.
Each test case in its first line contains two positive integer A and B (First 2 terms of GP).
In the second line o... |
c97b367857a07bbf4cbdf5b5617b308cd2db454a | saparia-data/data_structure | /geeksforgeeks/array/9_minimum_adjacent_difference_solved.py | 1,552 | 3.765625 | 4 | '''
Given an array Arr of N integers arranged in a circular fashion. Your task is to find the minimum absolute difference between adjacent elements.
Input:
The input line contains T, denoting the number of testcases. Each testcase contains two lines. The first line contains N(size of array). The second line contains N... |
6b915a5b53faff8c367b6427992436d6d8d76da8 | saparia-data/data_structure | /pepcoding/backtracking/21_permutation_of_words_1.py | 986 | 3.921875 | 4 | '''
1. You are given a word (may have one character repeat more than once).
2. You are required to generate and print all arrangements of these characters.
Sample Input:
aabb
Sample Output:
aabb
abab
abba
baab
baba
bbaa
https://www.youtube.com/watch?v=4-Makzrj5qM&list=PL-Jc9J83PIiHO9SQ6lxGuDsZNt2mkHEn0&index=23... |
f7ffa10d1e5c3f1201f358e15455cbd952f70baf | shavkat1717/dastur.uz_1000_ta_masala_04 | /24_masala.py | 106 | 3.65625 | 4 | x=int(input("x ni kiriting:"))
import math
if x>0:
print((math.sin(x))*2)
if x<=0:
print(x-6) |
54eb0ba58b950956c4bd4bd7c7f074cd4d39fb42 | shavkat1717/dastur.uz_1000_ta_masala_04 | /29_masala.py | 331 | 4 | 4 | x=int(input("Istalgan butun son kiriting: "))
if x>0 and x%2==0:
print("Ushbu son musbat juft son.")
elif x<0 and x%2==0:
print("Ushbu son manfiy juft son.")
elif x>0 and x%2!=0:
print("Ushbu son musbat toq son.")
elif x<0 and x%2!=0:
print("Ushbu son manfiy toq son.")
else:
print("Son no... |
19f609436808e5393281fadab46b19361ad6ffe7 | shavkat1717/dastur.uz_1000_ta_masala_04 | /26_masala.py | 120 | 3.859375 | 4 | x=float(input("x ni kiriting: "))
if x<=0:
print(-1*x)
elif 0<x<2:
print(pow(x,2))
elif x>=2:
print(4) |
132af496da7d7e0bea18d8dd078c718320821134 | shavkat1717/dastur.uz_1000_ta_masala_04 | /20_masala.py | 1,461 | 4.09375 | 4 | a=int(input("Sonlar o'qidagi 1-nuqtani kiriting A => "))
b=int(input("Sonlar o'qidagi 2-nuqtani kiriting B => "))
c=int(input("Sonlar o'qidagi 3-nuqtani kiriting С => "))
import math
if a<b<c:
print(f"A nuqtaga eng yaqin nuqta {b} va ular orasidagi masofa {math.fabs(b-a)} ga teng.")
if a<c<b:
print(f"A n... |
06ed6236fc7d5731b7c0d6d80054fe93a81d905f | gusar/Cloud-Computing | /lab2/euler19.py | 1,487 | 4.0625 | 4 | # NOT FINAL SOLUTION
# CHECK euler19v2.py
# This version uses nested for loops to cycle through years, months, weeks and days.
# Each time year changes, leap year is determined. Then every week the number of
# the days are calculated which belong to the current month.
# A separate counter keeps track of the current da... |
da72c5103bc2a0423412f0969a3ef7af8d3817c6 | kiarash-gh/Data-Structures-and-Algorithms | /Recursion/recursion.py | 330 | 3.90625 | 4 | # def recursive_methode(parameters):
# if exit conditon satisfied:
# return some value
# else:
# recursive_methode(modified parameters)
def recursive_methode(n):
if n < 1:
print("{} is less than 1".format(n))
else:
recursive_methode(n - 1)
print(n)
recursive_... |
655abf362be93f6b58938824d85fc5ae56df4f17 | bvschaik/advent-of-code | /2018/day13.py | 4,007 | 3.625 | 4 | import adventofcode
import re
RIGHT = 0
DOWN = 1
LEFT = 2
UP = 3
LEFT_DIR = [UP, RIGHT, DOWN, LEFT]
RIGHT_DIR = [DOWN, LEFT, UP, RIGHT]
class cart:
def __init__(self, x, y, direction):
self.x = x
self.y = y
self.direction = direction
self.intersect_count = 0
def move(self... |
00767750ee28df7ad669b318c4be8f3162934010 | STHale83/Python-func | /python func.py | 424 | 3.78125 | 4 | #'''def print_name(name): #name here is parameter
#print(name)
#print_name('Alex') #Alex here is argus'''
''' def foo(a,b,*args,**kwargs):
print(a,b)
for arg in args:
print(arg)
for key in kwargs:
print(key,kwargs[key])'''
#foo(1,2,3,4,5,six = 6, seven = 7)
#foo(1,2,... |
7fe54b433df2a57dc813822950f22a741d7beb97 | abid-mehmood/SP_Labs | /Labs/Python_homework/task4.py | 260 | 3.890625 | 4 | def remove_adjacent(name):
i=1
while i < (len(name)-1):
if name[i-1] == name[i] or name[i+1]== name[i]:
del name[i]
i-=1
i+=1
return name
if __name__=="__main__":
TempList=[1,2,2,2,2,3,4,5,5]
print TempList
print remove_adjacent(TempList)
|
6341dd84f1e64d14a82ec91f6e1a2ebbef02c49a | vortexus99/ucaccmet2j_python | /Part_3.py | 4,061 | 3.5 | 4 | #=============INSTRUCTIONS===============================#
#1 Rewrite your code so that it calculates all the above for each location
#(don't do this manually, but instead have Python read the station codes
#from the CSV).
#2 Calculate the relative precipitation over the whole year compared to the
#other stations_iden... |
f65a0cbac5567e01fc08e761c75219384c9631d2 | cginiel/si507 | /lecture/week2/dict_grades_example.py | 1,288 | 3.90625 | 4 |
students = {
'1001': {'last_name': 'Newman', 'first_name': 'Mark', 'uniqname': 'mwnewman'},
'1002': {'last_name': 'Kano', 'first_name': 'Tsuyoshi', 'uniqname': 'tkano'},
'1003': {'last_name': 'Grill', 'first_name': 'Gabriel', 'uniqname': 'ggrill'},
'1004': {'last_name': 'Chen', 'first_name': 'Kangning'... |
e76d09cc97d9d6d8677ae32ba52425ec5fa34a0f | cginiel/si507 | /lecture/week3/2020.01.21.py | 2,638 | 4.46875 | 4 | # # import datetime
# # date_now = datetime.datetime.now()
# # print(date_now.year)
# # print(date_now.month)
# # print(date_now.day)
# # print(type(date_now))
# # class is a type of thing, object is a particular instance of that class!!!!!
# # BEGIN CLASS DEFINITION
# """
# class Dog:
# def __init__(self, nm, ... |
c2d1ab4c0650b8d6283a86ac61a6438cfbe0b186 | jpchato/pdx_code | /programming_101/unit_1/exercise_3.py | 229 | 3.890625 | 4 | word = 'w'+'o'+'r'+'d'
print(word)
sentence = 'This ' + 'is ' + 'a ' + 'sentence.'
print(sentence)
xyz = 'T' + 'h' + 'i' + 's' + ' ' + 'i' + 's' + ' ' + 'a' + ' ' + 's' + 'e' + 'n' + 't' + 'e' + 'n' + 'c' + 'e' + '.'
print(xyz) |
8288e5fd26c497ab9b285289e0218d5ab2cba302 | jpchato/pdx_code | /programming_101/unit_3/exercise_1.py | 1,026 | 4.15625 | 4 | import math
# 1.1
tri_side_1 = 1
tri_side_2 = 2
hypotenuse = (tri_side_1*tri_side_1 + tri_side_2*tri_side_2)
def triangle_perimeter(tri_side_1, tri_side_2, hypotenuse):
print(tri_side_1 + tri_side_2 + hypotenuse)
return tri_side_1 + tri_side_2 + hypotenuse
# 1.2
def triangle_area(tri_side_2, tri_side_1):
... |
7027c29cdee9e42eba7c1c24cdad522128e3e482 | jpchato/pdx_code | /programming_101/unit_3/exercise_2.py | 564 | 3.9375 | 4 | # 2.1
def guess():
answer = 'z'
letter = input('Guess a letter: ')
if answer == letter:
print('correct answer')
else:
print('the correct answer was z')
# 2.2 & 2.3
def guess_again():
word = input('type a word: ')
letter = input('type a letter: ')
if letter in... |
644d28eaac478816daef87d5adb3de84e09f92d0 | alexbenko/pythonPractice | /misc/args.py | 139 | 3.71875 | 4 | def multiply(*args):
output = 1
for num in args[0]:
output *= num
return output
print(multiply([num for num in range(1,100)]))
|
1d07ee37723cc22548908a0a75b02facb6664100 | alexbenko/pythonPractice | /classes/magic.py | 787 | 4.125 | 4 | #how to use built in python methods like print on custom objects
class Car():
speed = 0
def __init__(this,color,make,model):
this.color = color
this.make = make
this.model = model
def __str__(this):
return f'Your {this.make},{this.model} is {this.color} and is currently going {this.speed} mph'
... |
bcd6cb98956568b63bcfae10ce07609a54dbc2fb | alexbenko/pythonPractice | /loops/dictionaryUnpack.py | 137 | 3.9375 | 4 | def unpackDictionary(data = {'a':"1",'b':"2",'c':"3"}):
for key,value in data.items():
print(key + ":" + value)
unpackDictionary() |
0f4df80809c941dcd5ae42ea1e5e95cd6274f7da | alexbenko/pythonPractice | /misc/zip.py | 256 | 3.96875 | 4 | def zipMaker(list1,list2):
return zip(list1,list2)
test1 = [1,2,3]
test2 = ['Applicant1', 'Applicant2', 'Applicant3']
zipped = zipMaker(test1,test2)
for item in zipped:
print(item)
#prints=>
#(1, 'Applicant1')
#(2, 'Applicant2')
#(3, 'Applicant3')
|
228e52139c941a5f1d9d59b5d9051e99abca07b2 | FlorentSimonnot/S6 | /Graphes/Rendu2_Nensy_SAM/SAM_Nensy.py | 11,106 | 3.703125 | 4 | """
Auteur : Nensy SAM
Groupe : G3
Rendu n°2
"""
class graphesOrientes(object) :
def __init__(self) :
self.dictionnaire = dict()
def ajouter_arc(self, u, v) :
"""Ajoute une arête entre les sommets u et v, en créant les sommets
manquants le cas échéant.
>>> G = graphesOrientes()
>>> G.ajouter_arc(... |
f3845857adc94a56f52445abeb016dca8b4a69f9 | JodanGalas/Python_para_zumbis | /Lista 04/Questão 04.py | 620 | 3.65625 | 4 | #04 -
lista = []
txt = ('''The Python Software Foundation and the global Python community
welcome and encourage participation by everyone.
Our community is based on mutual respect, tolerance,
and encouragement, and we are working to help each
other live up to these principles.
... |
4cdfd549b1cbe585b3a70e779c1ed3185e7ecf64 | JodanGalas/Python_para_zumbis | /Lista 02/Questão 01.py | 526 | 4.09375 | 4 | # 01 - Identificação de um triangulo.
a = int(input('Insira o primeiro lado de um triangulo: '))
b = int(input('Insira o segundo lado de um triangulo: '))
c = int(input('Insira o terceiro lado de um triangulo: '))
if a > (b + c) or b > (a + c) or c > (a + b):
print ('Não pode ser um triangulo')
elif a == b == c:
... |
022886ef14d5aca38f029734e33137f8d822d679 | PabloDavidBD/pythoncero | /emer | 261 | 4.0625 | 4 | #! /usr/bin/python
# -*- coding: iso-8859-15 -*-
numero = int(input("dime un numero: "))
if numero > 0:
print("El numero introducido es positivo")
elif numero <0:
print("El numero introducido es negativo")
else:
print("El numero introducido es 0") |
b1ec77cac2953516ced165066ea926e67f236c14 | xenron/sandbox-github-clone | /qiwsir/algorithm/delete_space.py | 508 | 4.375 | 4 | #! /usr/bin/env python
#coding:utf-8
#删除一个字符串中连续超过一次的空格。
def del_space(string):
split_string = string.split(" ") #以空格为分割,生成list,list中如果含有空格,则该空格是连续空格中的后一个
string_list = [i for i in string if i!=""]
result_string = " ".join(string_list)
return result_string
if __name__=="__main__":
one_str = "He... |
e4e03db41c9545833e67973a757590c103c72ad5 | xenron/sandbox-github-clone | /yubinbai/pcuva-problems/UVa 993 product of digits/main.py | 1,279 | 3.640625 | 4 | import sys
from collections import Counter
import math
def primeFactors(n):
'''
lists prime factors of a natural number, from greatest to smallest
'''
i = 2
result = []
while i <= math.sqrt(n):
while n % i == 0:
result.append(i)
n /= i
i += 1
if n !=... |
f2da950c646e625d86039ba8f962e9c9592b177e | xenron/sandbox-github-clone | /yubinbai/pcuva-problems/UVa 11110 Equidivisions/main.py | 1,381 | 3.53125 | 4 | import sys
from numpypy import *
def testColor(color, count):
def fillColor(i, j, c):
directions = [(i, j - 1), (i, j + 1), (i + 1, j), (i - 1, j)]
for i1, j1 in directions:
if i1 > 0 and i1 <= n and j1 > 0 and j1 <= n\
and graph[i1, j1] == c and not visited[i1, j1]... |
fa69edc32fa15fb3fbb865eb283ccbdb8a6b89b5 | xenron/sandbox-github-clone | /bmw9t/nltk/ch_three/19.py | 788 | 4.03125 | 4 | # Create a file consisting of words and (made up) frequencies, where each line consists of a word, the space character, and a positive integer,
# e.g. fuzzy 53. Read the file into a Python list using open(filename).readlines(). Next, break each line into its two fields using split(),
# and convert the number into an in... |
3ff3031ae43fcc4d3e8f231ce7ded1032f36df4a | xenron/sandbox-github-clone | /yubinbai/pcuva-problems/UVa 839 - Not so Mobile/main1.py | 577 | 3.625 | 4 | import sys
from collections import namedtuple
def weight():
try:
wl, dl, wr, dr = map(int, raw_input().split())
except:
return True, 0
leftB = rightB = True
if not wl:
leftB, wl = weight()
if not wr:
rightB, wr = weight()
if wl * dl == wr * dr and leftB and righ... |
25550a8e179e15cc048f37c282251fdaa1148ead | xenron/sandbox-github-clone | /xcv58/LeetCode/Linked-List-Cycle-II/Solution.py | 625 | 3.640625 | 4 | # Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# @param head, a ListNode
# @return a list node
def detectCycle(self, head):
n1 = head
n2 = head
while n2 is not None:
n1... |
9ac4b59f1f4a20ae2329aa4c0a979423e1081d55 | xenron/sandbox-github-clone | /algorhythms/LeetCode/357 Count Numbers with Unique Digits.py | 817 | 3.984375 | 4 | """
Given a non-negative integer n, count all numbers with unique digits, x, where 0 <= x < 10^n.
Example:
Given n = 2, return 91. (The answer should be the total numbers in the range of 0 <= x < 100, excluding
[11,22,33,44,55,66,77,88,99])
"""
__author__ = 'Daniel'
class Solution(object):
def countNumbersWithUn... |
50ab1fdf37f3d3702ef08d46c11fdd242559966d | xenron/sandbox-github-clone | /yubinbai/pcuva-problems/UVA 10042 Smith Numbers/main.py | 786 | 3.859375 | 4 | import sys
import math
def primeFactors(n):
'''
lists prime factors of a natural number, from greatest to smallest
'''
i = 2
while i <= math.sqrt(n):
if n % i == 0:
l = primeFactors(n / i)
l.append(i)
return l
i += 1
return [n] # n is prime
... |
60464211e844cf2a83e16eef41e6aa66a7d521a3 | xenron/sandbox-github-clone | /jw2013/Leetcode-Py/Symmetric Tree.py | 492 | 3.765625 | 4 | class Solution:
def isSymmetric(self, root):
if root is None:
return True
return self.isSymmetricRecur(root.left, root.right)
def isSymmetricRecur(self, left, right):
if left is None and right is None:
return True
if left is None or right... |
21d8954df6f0602c262d6776a1ee12f6aed41fc9 | xenron/sandbox-github-clone | /qiwsir/algorithm/change_coin.py | 2,742 | 4 | 4 | #!/usr/bin/env python
#coding:utf-8
"""
问题:
以人民币的硬币为例,假设硬币数量足够多。要求将一定数额的钱兑换成硬币。要求兑换硬币数量最少。
思路说明:
这是用贪婪算法的典型应用。在本例中用python来实现,主要思想是将货币金额除以某硬币单位,然后去整数,即为该硬币的个数;余数则做为向下循环计算的货币金额。
这个算法的问题在于,得出来的结果不一定是最有结果。比如,硬币单位是[1,4,6],如果将8兑换成硬币,按照硬币数量最少原则,应该兑换成为两个4(单位)的硬币,但是,按照本算法,得到的结果是一个6单位和两个1单位的硬币。这也是本算法的局限所在。所谓贪婪算法,本质就是只要找出一个结... |
d32608baef12a1b91023cfae37bfdae3248e7ba7 | xenron/sandbox-github-clone | /yubinbai/pcuva-problems/UVa 718 Skyscraper Floors/main.py | 839 | 3.703125 | 4 | import sys
def find(i):
if parent[i] != i:
parent[i] = find(parent[i])
return parent[i]
def union(i, j):
p1 = i
while parent[p1] != p1:
p1 = parent[p1]
p2 = j
while parent[p2] != p2:
p2 = parent[p2]
if rank[p1] < rank[p2]:
parent[p1] = p2
else:
... |
4b3d8e345f498c6950b54a45a69258fa58b14949 | xenron/sandbox-github-clone | /jw2013/Leetcode-Py/Search for a Range.py | 1,350 | 3.53125 | 4 | class Solution:
def searchRange(self, A, target):
left = self.searchRangeRecur(A, target, lambda x, y: x >= y, 0, len(A) - 1)
if left >= len(A) or A[left] != target:
return [-1, -1]
right = self.searchRangeRecur(A, target, lambda x, y: x > y, 0, len(A) - 1) - 1
retu... |
7ff9d89e9520ae076c9b276a996677cfe65eaccb | xenron/sandbox-github-clone | /yubinbai/pcuva-problems/UVa 494 - Kindergarten Counting Game/main.py | 118 | 3.703125 | 4 | import re
inFile = open('input.txt')
for line in inFile:
row = re.findall('[a-zA-Z]+', line)
print(len(row))
|
f11e7df3f14cd9e8cec3516b771bc507ba5ab751 | xenron/sandbox-github-clone | /xcv58/LeetCode/Sqrt/Solution.py | 549 | 3.703125 | 4 | class Solution:
# @param x, an integer
# @return an integer
def sqrt(self, x):
root = 1;
tmpInt = x;
while tmpInt > root:
root = root << 1
tmpInt = tmpInt >> 1
mid = (root + tmpInt) / 2
while tmpInt +1 < root:
tmpResult = x / mid;... |
8b4129a3e214252e0ba10629b66200b6670df4df | xenron/sandbox-github-clone | /xcv58/LeetCode/Remove-Duplicates-from-Sorted-List/Solution.py | 521 | 3.6875 | 4 | # Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# @param head, a ListNode
# @return a ListNode
def deleteDuplicates(self, head):
anchor = head
base = head
while anchor is not None a... |
478ea15d1ca63df73b4a8d7ecd1c9ec3ece8a3d7 | xenron/sandbox-github-clone | /bmw9t/nltk/ch_four/13.py | 564 | 3.921875 | 4 | # ◑ Write code to initialize a two-dimensional array of sets called word_vowels and process a list of words, adding each word to word_vowels[l][v] where l is the length of the word and v is the number of vowels it contains.
m, n = 2, 8
word_vowels = [[set() for i in range(m)] for j in range(n)]
sent = ['this', 'is',... |
f6b22ef1f17e047f07f2741db2b41de13337a560 | xenron/sandbox-github-clone | /qiwsir/algorithm/perfect_number.py | 697 | 3.875 | 4 | #!/usr/bin/env python
#coding:utf-8
"""
找出完全数
"""
#找出一个数的因数
def factors(n):
#return [i for i in range(1,n/2+1) if n%i == 0]
#如果仅仅是为了得到因数,可以用上面的
#如果是配合下面完全数,最好使用下面的。因为在下面少循环一次,1肯定是任何整数的因数
return [i for i in range(2,n/2+1) if n%i == 0]
#找出某个数n以内的所有完全数,即在[1,n]内(含n)
def perfect(n):
#从上面的factors中得到的因数... |
286630c8b46a06757cc3c54d06e6a89f0c7b89ab | xenron/sandbox-github-clone | /yubinbai/pcuva-problems/UVa 10929 you can say 11/main.py | 329 | 3.5 | 4 | import sys
sys.stdin = open('input.txt')
while True:
s = raw_input().strip()
if s == '0':
break
n = map(int, s)
total = 0
for i, d in enumerate(n):
total += d * (-1) ** i
if total % 11:
print '%s is not a multiple of 11.' % s
else:
print '%s is a multiple of ... |
b8223e559d226b426a3eb75adff92a8320a9a804 | xenron/sandbox-github-clone | /xcv58/LeetCode/Populating-Next-Right-Pointers-in-Each-Node/Solution.py | 678 | 3.921875 | 4 | # Definition for a binary tree node
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
# self.next = None
class Solution:
# @param root, a tree node
# @return nothing
def connect(self, root):
while root is not None:
... |
83a03d226c6e10de0898360d7ebbc0ba00b0c6cc | xenron/sandbox-github-clone | /xcv58/LeetCode/Search-a-2D-Matrix/Solution.py | 583 | 3.546875 | 4 | class Solution:
# @param matrix, a list of lists of integers
# @param target, an integer
# @return a boolean
def searchMatrix(self, matrix, target):
if len(matrix) == 0:
return False
n = len(matrix[0])
i = 0
j = n * len(matrix)
while i < j:
... |
5276845553419db538e90b312ae5cd6745280424 | xenron/sandbox-github-clone | /kamyu104/GoogleCodeJam-2015/Qualification Round/infinite-house-of-pancakes.py | 668 | 3.5625 | 4 | # Copyright (c) 2015 kamyu. All rights reserved.
#
# Google Code Jam 2015 Qualification Round - Problem B. Infinite House of Pancakes
# https://code.google.com/codejam/contest/6224486/dashboard#s=p1
#
# Time: O(max(P) * D)
# Space: O(1)
#
def pancake():
D = int(input())
P = map(int, raw_input().strip().split(... |
51815e5002ff1de64cf7096b018580c8b4b37197 | xenron/sandbox-github-clone | /wizcabbit/leetcode.python/098.Validate.Binary.Search.Tree.py | 1,237 | 3.953125 | 4 | # *********************************************
# Source : https://oj.leetcode.com/problems/validate-binary-search-tree/
# Author : wizcabbit
# Date : 2014-11-09
# Given a binary tree, determine if it is a valid binary search tree (BST).
# Assume a BST is defined as follows:
# The left subtree of a node contains o... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.