Found 27104 Articles for Server Side Programming

Print numbers in the range 1 to n having bits in an alternate pattern

Divya Sahni
Updated on 28-Sep-2023 14:26:29

64 Views

Alternate bit pattern implies the positioning of 0’s and 1’s in a number at an alternate position i.e. no two 0s or 1’s are together. For example, 10 in binary representation is (1010)2 which has an alternate bit pattern as 0’s and 1’s are separated by each other. Problem Statement Given an integer, N. Find all the integers in the range 1 to N where the bit pattern of the integer is alternating. Example 1 Input: 10 Output: 1, 2, 5, 10 Explanation $\mathrm{(1)_{10} = (1)_2, (2)_{10} = (10)_2, (5)_{10} = (101)_2, (10)_{10} = (1010)_2}$ Example 2 Input: ... Read More

Jacobsthal and Jacobsthal-Lucas Numbers

Divya Sahni
Updated on 28-Sep-2023 14:19:17

160 Views

Jacobsthal Numbers Lucas sequence 𝑈𝑛(𝑃, 𝑄) where P = 1 and Q = -2 are called Jacobsthal numbers. The recurrence relation for Jacobsthal numbers is, $$\mathrm{𝐽_𝑛 = 0\: 𝑓𝑜𝑟 \: 𝑛 = 0}$$ $$\mathrm{𝐽_𝑛 = 1\: 𝑓𝑜𝑟 \: 𝑛 = 1}$$ $$\mathrm{𝐽_𝑛 = 𝐽_𝑛−1 + 2𝐽_{𝑛−2}\: 𝑓𝑜𝑟 \: 𝑛 > 1}$$ Following are the Jacobsthal numbers − 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, 683, 1365, …. Jacobsthal-Lucas Numbers Complementary Lucas sequence $\mathrm{𝑉_𝑛(𝑃, 𝑄)}$ where P = 1 and Q = -2 are called JacobsthalLucas numbers. The recurrence relation for Jacobsthal-Lucas numbers is, $\mathrm{𝐽_𝑛}$ = ... Read More

How to create HTTPS Server with Node.js?

Aayush Mohan Sinha
Updated on 07-Sep-2023 17:08:35

706 Views

As the consumption of the cyberspace and cloud-dependent applications proliferates, the gravity of safeguarding online data and transactions becomes more apparent. One of the most commonly employed methodologies for securing online communications is HTTPS, which provides an assurance that the information conveyed between the server and clients is ciphered and cannot be effortlessly intercepted by malevolent third parties. In this manuscript, we will probe into the process of building an HTTPS server with Node.js, an influential and adaptable platform for developing server-side applications using JavaScript. We will go over the fundamentals of SSL certificates, the essential components of an HTTPS ... Read More

How to iterate a loop with index and element in Swift?

Nitin Aggarwal
Updated on 07-Sep-2023 14:25:38

794 Views

In this article, you will learn how to iterate a collection using a loop with an index and element in the Swift language. In this article, you will learn how to use the enumerated() method. In Swift, you can use the enumerated() method to iterate over the elements of a collection and access both the index and the element in each iteration of the loop. enumerated() enumerated() is a method in Swift that allows you to iterate over the elements of a collection, such as an array or a dictionary. It returns a series of tuple elements, each of which ... Read More

How to check if an element is in an array?

Nitin Aggarwal
Updated on 07-Sep-2023 14:10:43

125 Views

This article will explain how you can check if an element exists in an array or not in the Swift language. There are several ways to check if an element is in an array in Swift − Using the contains method The contains(_:) method returns true if an array contains the target element. This method can only be used with arrays whose elements conform to the Equatable protocol. Here is an example where we use contains with an array of strings. String conforms to the Equatable protocol, so we can use the contains method here. Algorithm Step 1 - ... Read More

How do I shuffle an array in Swift?

Nitin Aggarwal
Updated on 07-Sep-2023 09:14:06

154 Views

In this article, you will learn how to shuffle an array in the Swift language. In Swift, you can use the shuffle() and shuffled() methods to shuffle the array elements. shuffle() The shuffle() method shuffles the elements of the collection in place, so the original array is modified. shuffled() If you want to create a shuffled copy of the array instead of modifying the original array, you can use the shuffled() method from the Sequence protocol. Here is an example of how to use shuffle() to shuffle the array elements Algorithm Step 1 - Create an input array Step ... Read More

How do I make an attributed string using Swift?

Nitin Aggarwal
Updated on 07-Sep-2023 09:10:50

316 Views

This article will explain how you can make an attributed string in the Swift language. What are the steps to apply different attributes to a string in Swift? In Swift, we use the NSAttributedString class to make an attributed string. In Swift, NSAttributedString is a class used to create and manage attributed strings. An attributed string is a string that has additional attributes, such as text color, font, and style, applied to parts of the string. This article will show different use cases for an attributed string. Basic Setup import UIKit class TestController: UIViewController { private ... Read More

How do I change the font size of a UILabel in Swift?

Nitin Aggarwal
Updated on 07-Sep-2023 08:58:53

1K+ Views

You can change the font size of a UILabel in Swift by setting the font property of the UILabel to a UIFont object with the desired point size. Here is the code for the basic setup import UIKit class TestController: UIViewController { private let messageLabel = UILabel() override func viewDidLoad() { super.viewDidLoad() initialSetup() } ... Read More

How do I add 1 day to an NSDate?

Nitin Aggarwal
Updated on 07-Sep-2023 08:55:29

108 Views

In this article, you will learn how to add the number of days to a date in the Swift language. Many times, you might need to modify the date by changing some number of days, weeks, months, etc. Swift provides an in-built concept for adding a component to date. Let's see some examples. Let's take a brief look at a few of the common concepts that will be used in these examples. Calendar Class The Calendar class in Swift is a class that represents a calendar, which is a system for organizing dates. It is used to perform calendar-related calculations, ... Read More

Getting a "This application is modifying the autolayout engine from a background thread" error?

Nitin Aggarwal
Updated on 07-Sep-2023 08:50:34

70 Views

In iOS development, this error frequently occurs while working on user interfaces. Also, you can reduce the chances of coming across this error if you write code carefully. Let's understand what this error is all about. It will help you to understand the reason behind this error if you read the error statement. The error "This application is modifying the autolayout engine from a background thread" is caused when an application attempts to make changes to the user interface from a background thread, which is not allowed in iOS development. Autolayout is a system for defining the layout of user ... Read More

Advertisements