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
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
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
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
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
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
In Swift, you can use the weak keyword to declare an array of weak objects. In this article, we will use the weak keyword to store the weak objects or references in an array. Weak References Weak references are one of the solutions to the retain cycle problem in Swift. Note that a weak reference does not increment or decrement the reference count of an object. They can be deallocated even if ARC has a reference count greater than 1. Basically, we use the weak keyword in Swift to mark a reference as weak. Also, a weak reference cannot be ... Read More
What is a Generalized Number System? A mathematic structure which can extend the properties of the conventional number system like integers, real numbers, rational numbers, complex numbers, etc. to a more general case is known as a generalized number system. The major applications of generalized number systems include many areas of mathematics such as algebra, analysis, number theory, topology, etc. In more simple terms, a generalized number system can be defined as the generalization of the conventional/traditional number systems. Importance of Generalized Number Systems Generalized number systems are considered an important part of modern mathematics and science because they provide ... Read More
In Swift, there are some directives to perform some checks at compilation time. Based on that, you can perform initial checks to write better code. In this article, we will see how to use the "#warning" directive with some examples. You can use the #warning directive to issue a warning message at compile-time. This is similar to the #warning directive in C and Objective-C. #warning in Swift In Swift, #warning is a compiler directive that allows you to issue a warning message during compilation. This can be useful for reminding yourself or other developers about areas of the code that ... Read More
Let's start this article with a basic overview of flip-flops before moving onto discuss how they can be used as a divider circuit. What is a Flip-Flop? In digital electronics, a flip-flop (FF) is a sequential logic circuit which is used for storing 1-bit of information. As we know, in digital systems, information is represented in binary form, i.e. in terms of 0 and 1. Where, a binary 0 and a binary 1 is referred to as a bit. A flip-flop is a 1-bit memory cell that stores information in terms of 0 or 1. Therefore, flipflop is the fundamental ... Read More