Programming Articles

Page 537 of 2547

Base 3 to integer in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Converting a base 3 number to decimal involves multiplying each digit by the appropriate power of 3. Python provides several methods to perform this conversion efficiently. Understanding Base 3 to Decimal Conversion In base 3, each digit position represents a power of 3. For example, "10122" in base 3 equals: 1×3⁴ + 0×3³ + 1×3² + 2×3¹ + 2×3⁰ = 81 + 0 + 9 + 6 + 2 = 98 Method 1: Using Horner's Method This efficient algorithm processes digits from left to right, accumulating the result ? def base3_to_decimal(s): ...

Read More

Austin Powers in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 153 Views

Suppose we have a number greater than 0, we have to check whether the number is a power of two or not. A power of two is any number that can be expressed as 2n where n is a non-negative integer (1, 2, 4, 8, 16, 32, etc.). So, if the input is like 1024, then the output will be True because 1024 = 210. Approach To solve this, we will follow these steps ? While n > 1, do n := n / 2 Return true when n is same as ...

Read More

Atbash cipher in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 3K+ Views

The Atbash cipher is a simple substitution cipher where each letter is mapped to its reverse position in the alphabet. In this cipher, 'a' becomes 'z', 'b' becomes 'y', and so on. Let's explore how to implement this cipher in Python. Understanding the Atbash Cipher The Atbash cipher works by reversing the alphabet: Original: a b c d e f g h i j k l m n o p q r s t u v w x y z Atbash: z y x w v u t s r q p o n m ...

Read More

A strictly increasing linked list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 329 Views

A strictly increasing linked list is one where each node's value is greater than the previous node's value. We need to traverse the list and check if the values are in strictly ascending order. So, if the input is like [2, 61, 105, 157], then the output will be True because each element is greater than the previous one. Algorithm To solve this, we will follow these steps − Define a function solve() that takes the head of the linked list If head.next is null, return True (single node is considered strictly increasing) If head.val ...

Read More

A number and its triple in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 782 Views

When working with lists of numbers, you might need to check if any number in the list is exactly triple another number. This problem can be solved efficiently using a two-pointer approach after sorting the list. For example, if we have nums = [2, 3, 10, 7, 9], the output should be True because 9 is the triple of 3. Algorithm Steps To solve this problem, we follow these steps ? Sort the list to enable two-pointer technique Initialize two pointers: i = 0 and j = ...

Read More

Ancient Astronaut Theory in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 257 Views

The Ancient Astronaut Theory problem involves checking if a string follows a custom lexicographic ordering defined by an ancient astronaut dictionary. Given a dictionary string that represents the order of characters, we need to verify if the input string is sorted according to this custom order. For example, if the dictionary is "bdc", then 'b' comes before 'd', and 'd' comes before 'c' in this custom ordering. Problem Understanding Given a dictionary string and an input string, we need to check if the characters in the input string appear in the same order as defined by the ...

Read More

Acronym in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

An acronym is formed by taking the first letter of each word in a phrase. In Python, we can create acronyms by splitting the phrase into words and extracting the first character of each word, excluding common words like "and". Problem Statement Given a string representing a phrase, we need to generate its acronym. The acronym should be capitalized and exclude the word "and". For example, if the input is "Indian Space Research Organisation", the output should be "ISRO". Algorithm To solve this problem, we follow these steps ? Split the string into ...

Read More

Accumulator battery in Python

Akshitha Mote
Akshitha Mote
Updated on 25-Mar-2026 392 Views

Consider a mobile phone in eco mode that activates when battery level reaches 20%. In eco mode, the battery drains two times slower than normal mode. Given the current time t and battery percentage p, we need to calculate how many minutes remain until the phone turns off. Problem Statement In normal mode, if the battery drains 1% per minute, then in eco mode it drains 1% per 2 minutes (half the rate). Starting with 100% battery, after t minutes we have p percent remaining. We must find the time until complete drain. Example Scenario If ...

Read More

3 and 7 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 418 Views

Sometimes we need to determine if a positive number can be expressed as a sum of non-negative multiples of 3 and 7. This problem involves checking if n = a×3 + b×7 where a and b are non-negative integers. For example, 13 can be written as 1×7 + 2×3 = 13, so the answer is True. Algorithm The approach is to iterate through all possible multiples of 7 up to n and check if the remainder is divisible by 3 − For each multiple of 7 from 0 to n (step by 7) Check if ...

Read More

3-6-9 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

The 3-6-9 game is a popular counting game where players replace certain numbers with a special word. In this Python implementation, we create a list from 1 to n, but replace numbers that are multiples of 3 or contain the digits 3, 6, or 9 with the string "clap". Problem Statement Given a number n, construct a list with each number from 1 to n as strings, except when the number is a multiple of 3 or contains the digits 3, 6, or 9 − replace these with "clap". For example, if the input is 20, the ...

Read More
Showing 5361–5370 of 25,466 articles
« Prev 1 535 536 537 538 539 2547 Next »
Advertisements