Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Monday, 10 June 2013

Python Puzzles: PART - 1

  The following Python Puzzle is taken from the Programming Practice site CodingBat. I have written about CodingBat in the previous post.

The Puzzle is given below.

We have to make a row of bricks that is goal inches long. There are a number of small bricks (1 inch each) and big bricks (5 inches each). Return True if it is possible to make the goal by choosing from the given bricks. You should not use any loops.

The function make_bricks( ) is called as follows,
make_bricks(small, large, goal) : Here small is the number of small bricks, large is the number of large bricks and goal is the length of the row to be constructed.

The Figure Below Shows a Sample Output

Thursday, 30 May 2013

Python Module to Check whether a Number is Pandigital or Not

  This Python module checks whether a given number is Pandigital or not. A number is said to be Pandigital if it contains each of the digits from 0 to 9. For example, 123456789000 is a Pandigital number in base 10.

Figure Below Shows a Sample Output


Python Module to find the Factors of a Number

  This module finds the factors of a given number. This a very useful module for solving many larger problems.

Figure Below Shows a Sample Output

Python Module to Check the Primality of a Number

  This Python module checks whether a given number is prime or not. This module is quite useful in solving many larger problems.

Figure Below Shows a Sample Output

Python Module to Remove Duplicate Elements from a List

  This module helps you to remove duplicate elements from a list. This module is very useful in solving many other larger problems. I have used this module to solve a few problems in Project Euler.

Figure Below Shows a Sample Output

Python Module to Print Fibonacci Numbers

  A module in Python is a file containing Python definitions and statements. This module helps you to print and return the list of Fibonacci numbers less than a given number n.

Figure Shows a Sample Output