Python 21 days of Code Golf
Greetings!! Here's a series of Cold Golf problems and solutions in Python as a part of 21 days of Code | Code Golf by Skillenza
https://skillenza.com/challenge/21days-of-code
DAY - I
A Little Complex
Given n complex numbers each x + yi, where x is the real part and y is the imaginary part, find
Python Deque - Postfix to infix raw expression
Hey guys, Hope you all are doing great.
Algorithm To Convert Post-fix Expression into Infix expression:-
Scan the Post-fix String from Left to Right. If the character is an Operand, then Push it on to the deque.
Python package and installation - Pip vs Conda
Hey guys, Hope you all are doing great.
As the first part of this series of Python package and installation we will cover pip vs Conda
pip vs Conda
pip
Python packages only. Compiles everything from source.
Code Golf - Kurteous Tips and Tricks
Hey guys,
Hope you all are doing great. I love Code Golfing, what it brings out in you is the hidden concepts of a programming language and especially the push to implement same thing in numerous ways.
Hey guys, Hope you all are doing great.
I have always found Regular expressions or REGEX quite amazing. You can solve your string related problem in just some simple magic of patterns.
Our brain works very well to identify the pattern in our day to day life.
Code Golf Python Tips and Tricks Part-2
Hey guys, Hope you all are doing great. I am back with Some Python Programming tips for
CODE GOLF Challenges.
Project Euler #11: Largest product in a grid
Hey guys, Hope you all are doing great. I am back with another problem of Project Euler on
Project Euler #11: Largest product in a grid
In the 20×20 grid below, four numbers along a diagonal line have been marked in bold.
Tabibitosan method - A bow to Aketi Jyuuzou
Hey guys, Hope you all are doing great.
Today i came across an intruding method, which is not used in generally but is very effective and we encounter its application a lot of .
That's
Tabibitosan method
Tabibitosan: is a Japanese word which literally means "Pilgrim".
Project Euler #10: Summation of primes
Hey guys,
Hope you all are doing great. I am back with another problem of Project Euler on
The sum of the primes below 10 is 2+3+5+7=17
Find the sum of all the primes not greater than given N.
Input Format
The first line contains an integer T i.e. number of the test cases.
Hey guys,
Hope you all are doing great. I am back with another problem of Project Euler on
The sum of the primes below 10 is 2+3+5+7=17
Find the sum of all the primes not greater than given N.
Input Format
The first line contains an integer T i.e. number of the test cases.
The next T lines will contains an integer N.
Output Format
Print the value corresponding to each test case in separate line.
Constraints
1≤T≤104
1≤N≤106
Sample Input
2
5
10
Sample Output
10
17
Algorithm:
The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Implement this algorithm, with the only allowed optimization that the outer loop can stop at the square root of the limit, and the inner loop may start at the square of the prime just found. That means especially that you shouldn't optimize by using pre computed wheels, i.e. don't assume you need only to cross out odd numbers (wheel based on 2), numbers equal to 1 or 5 modulo 6 (wheel based on 2 and 3), or similar wheels based on low primes.
Odds-only version of the array sieve above
The below code uses only odd composite operations (for a factor of over two) and because it has been optimized to use slice operations for composite number culling to avoid extra work by the interpreter
Program:
def primes2(limit):
if limit < 2: return []
if limit < 3: return [2]
lmtbf = (limit - 3) // 2
buf = [True] * (lmtbf + 1)
for i in range((int(limit ** 0.5) - 3) // 2 + 1):
if buf[i]:
p = i + i + 3
s = p * (i + 1) + i
buf[s::p] = [False] * ((lmtbf - s) // p + 1)
return sum([2] + [i + i + 3 for i, v in enumerate(buf) if v])
t=input()
while(t>0):
print primes2(input())
t-=1
Hope you liked this post.
Do let me know about any improvements i can incorporate to anything in the blog.
Till Then...Cheers!!
Print Prime Numbers in SQL
Hey guys, Hope you all are doing great. I am back with a new domain SQL. So the problem goes like, you need to print prime numbers less than 1000.
Seems easy right!! Just use a for loop check for the list of natural numbers for prime condition whether they are only divisible by 1 and itself.
Hey guys,
Hope you all are doing great. I am back with another problem of Project Euler on
Project Euler #8: Largest product in a series
Find the greatest product of KK consecutive digits in the NN digit number.
Input Format
First line contains TT that denotes the number of test cases.
Hey guys,
Hope you all are doing great. I am back with another problem of Project Euler
Project Euler #2: Even Fibonacci numbers
Each new term in the Fibonacci sequence is generated by adding the previous two terms.
Hey guys,
Hope you all are doing great. I am back with another problem of Project Euler on
Project Euler #6: Sum square difference
The sum of the squares of the first ten natural numbers is, 12+22+...+102=385. The square of the sum of the first ten natural numbers is, (1+2+⋯+10)2=552=3025.
Hey guys,
Hope you all are doing great. I am back with another problem of Project Euler on
Project Euler #5: Smallest multiple
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
Hey guys,
Hope you all are doing great. I am back with another problem of Project Euler on
Project Euler #3: Largest prime factor
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of a given number N?
Input Format
First line contains T, the number of test cases.
Hey Fellas!! So its time to roll on.
Mathematical series are very interesting in there own ways. I find them interesting as they tickles your brain to know more.
That you try to find the end. Counting on your fingers, you will get bored or either get tired.
One of the Popular contest in Hackerrank based on a famous site ProjectEuler.net is
Project Euler+
Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve.
Add a comment