Found 33676 Articles for Programming

Haskell Program to Print Right Triangle Star Pattern

Akhil Sharma
Updated on 24-Apr-2023 11:39:31

296 Views

In haskell we can use mapM, forM as well as recursive function to create a simple right triangle star pattern. What is a Right Triangle Star Pattern? A right triangle pattern is a series of asterisks or other characters arranged in a triangular shape. In the case of a right triangle pattern, the base of the triangle is the longest side and is aligned with the horizontal axis, while the other two sides form a right angle. The number of asterisks or characters in each row of the triangle decreases as you move up the triangle, so that the top ... Read More

Haskell Program To Find The Perfect Number

Akhil Sharma
Updated on 24-Apr-2023 11:37:54

498 Views

In haskell we can use list comprehension and brute-force method to find the perfect number. What is a Perfect Number? Perfect numbers are positive integers that are equal to the sum of their proper divisors. A divisor of a positive integer n is a positive integer that divides n exactly, leaving no remainder. A proper divisor is a divisor of n that is less than n itself. For example, the proper divisors of 6 are 1, 2, and 3, and the sum of these divisors is 1 + 2 + 3 = 6. Therefore, 6 is a perfect number.. Algorithm ... Read More

Haskell Program to Check Whether a Number is Prime or Not

Akhil Sharma
Updated on 24-Apr-2023 11:37:11

911 Views

To check whether a given number is prime or not we are going to use mod function and list comprehension method in Haskell. What is a Prime Number? A prime number is a positive integer greater than 1 that is only divisible by 1 and itself. In other words, a prime number cannot be written as the product of two smaller positive integers, except for 1 and itself. For example, the first few prime numbers are: 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29. Algorithm Step 1 − The isPrime function is defined. Step 2 ... Read More

Haskell Program to Check if two strings are anagram

Akhil Sharma
Updated on 24-Apr-2023 11:36:12

510 Views

In Haskell we can check if given two strings are anagram or not using sort function and freqMap. What is Anagram? An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. For example, the word "listen" is an anagram of the word "silent". Anagrams are often used in word play, puzzles, and other forms of entertainment. Algorithm Step 1 − The Data.List module is imported to use sort function. Step 2 − The isAnagram function using sort function is defined Step 3 ... Read More

Haskell Program to Check if a String is Numeric

Akhil Sharma
Updated on 14-Jul-2023 16:53:27

2K+ Views

In Haskell we can use read functions and Data.char library to find if a given string is numeric or not. The following example will give you a clear idea about the valid numeric values. For example, 121, 12321, and 1221 if entered as string are valid numeric values. Algorithm Step 1 − The isNumeric function using reads function is defined Step 2 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. In the main function, the string is passed to the isNumeric function. ... Read More

Haskell Program to Check Palindrome

Akhil Sharma
Updated on 24-Apr-2023 11:34:26

1K+ Views

This tutorial will help us in checking if any number is palindrome number or not using user-defined function and boolean functions in haskell. A palindrome number is a number that remains the same when its digits are reversed. The following example will give you a clear idea about Palindrome number. For example, 121, 12321, and 1221 are palindrome numbers, while 123, 1234, and 1212 are not. Algorithm Step 1 − The isPalindrome function using reverse function is defined as, isPalindrome str = str == reverse str. Step 2 − Program execution will be started from main function. The ... Read More

Haskell Program to create Complex numbers from given imaginary parts

Akhil Sharma
Updated on 24-Apr-2023 11:33:39

328 Views

In this article we are going to use the internal function of Haskell like Data.complex and Prelude to create a complex number from a given imaginary parts. This tutorial will help us in creating the complex number from the given imaginary part. The imaginary part of a complex number is the coefficient of the imaginary unit, typically represented by the symbol "i", in the standard form of the complex number. A complex number can be represented in standard form as a + bi, where a is the real part and b is the imaginary part. Algorithm Step 1 − ... Read More

Python Program to get first and last element from a Dictionary

Utkarsha Nathani
Updated on 24-Apr-2023 13:24:14

24K+ Views

Python is an interpreted, object–oriented, high level, programming language with dynamic semantics. Developed by Gudio Van Rossum in 1991. It supports multiple programming paradigms, including structured, object-oriented and functional programming. Before diving deep into the topic let’s first brush up the basic concepts related to the question provided to us. A dictionary is a group of items that are unique, changing, and ordered. Curly brackets are used in dictionary writing, and they contain keys and values: The key name can be used to refer to dictionary objects. Data values are kept as key:value pairs in dictionaries. Ordered and unordered ... Read More

Python program to remove null values from a dictionary

Utkarsha Nathani
Updated on 24-Apr-2023 12:08:57

3K+ Views

Dictionaries are known as the collection data types. They store data in the form of key value pair. They are ordered and changeable i.e., they follow a particular sequence and are indexed. We can change the values for a key and therefore it is manipulative or changeable. Dictionaries does not support duplication of data. Each key can have multiple values associated with it but a single value cannot have more than one key. We can use dictionaries to perform numerous operations. The entire mechanism depends upon the stored values. In this article, we will discuss the techniques that can be ... Read More

Python Program To Find The Largest Element In A Dictionary

Utkarsha Nathani
Updated on 24-Apr-2023 12:07:45

304 Views

Dictionaries are used to store data values in key:value pairs like maps (which unlike other data types holds only a single value as an element). key:value is provided in dictionaries to make it more effective. Keys are unique. Dictionary key must be unique. So, no duplicate values are allowed in dictionaries. Dictionaries items are ordered, changeable, immutable. Changeable means here is that, we can add or remove items after the dictionaries are created. In this article, we will know about how to find a largest element in a dictionary by using different functions. There are many functions to find ... Read More

Advertisements