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
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.
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.
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.
Hey guys, Hope you all are doing great. I am back with Some Python Programming tips for

CODE GOLF Challenges.
Hey guys, Hope you all are doing great. I am back with Some Python Programming tips for

CODE GOLF Challenges.
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.
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".
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 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 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.

But if you are asked to do it only using plain SQL, i will be using Oracle in my case, how would you do that.

In PL/SQL its possible with straight approach, but in SQL its bit tricky.Lets start....

Write a query to print all prime numbers less than or equal to 1000. Print your result on a single line, and use the (,) character as your separator (instead of a space).
For example, the output for all prime numbers  would be:
2,3,5,7

Algorithm:


1. First we will generate the numbers from 1 to 1000. This can be achieved by using level connect in SQL i.e. Hierarchical SQL. A condition that identifies the relationship between parent rows and child rows of the hierarchy. So we will get number 1, 2, 3.....1000.
This is how it will look on Oracle SQL format....

select level l from dual connect by level  <= 1000



2. Now we can use above query to generate another set of numbers and proceed with our logic.
So for checking the prime condition there should be a number which is when divided return 0 as remainder only 2 times, that is divided by 1 and divided by num (number itself).

So we have a condition a SQL where we have Count = 2


This is how we can implement it:



select l prime_number
from (select level l from dual connect by level <= 1000)
, (select level m from dual connect by level < = 1000)
where m<=l
group by l
having count(case l/m when trunc(l/m) then 'Y' end) = 2;

Output of above looks like:

PRIME_NUMBER
43
83
151
167
173
179
227
269

 

3. Now for the final step we need to connect the output is separate lines to single line output separated by comma (,). For this purpose we will use LISTAGG function in SQL

Program/Script:
So our final script looks like...

SELECT LISTAGG(prime_number,',') WITHIN GROUP (ORDER BY prime_number) AS NUMBERS
FROM(    
    select l prime_number
from (select level l from dual connect by level <= 1000)
, (select level m from dual connect by level <= 1000)
where m<=l
group by l
having count(case l/m when trunc(l/m) then 'Y' end) = 2);

Output will be


2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997 

Hope you guys find my post useful, let me know how i can improve....
Till then. Take care!!




13

View comments

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.
Loading