Functional Programming Techniques in Haskell: A Practical Guide

1. Merging Two Sorted Lists

Task

Merge two sorted lists into one sorted list.

Solution

Base cases handle empty lists; recursive case merges elements based on comparison.

merge :: [Integer] -> [Integer] -> [Integer]
merge [] ys = ys
merge xs [] = xs
merge (x:xs) (y:ys)
  | x <= y     = x : merge xs (y:ys)
  | otherwise = y : merge (x:xs) ys

2. Splitting a List

Task

Split a list into two approximately equal parts.

Solution

Use pattern matching and recursion to alternate elements into two lists.

split 
Read More

Understanding Database Schemas: A Comprehensive Guide

What is a Database?

A database is a collection of related data, which refers to known facts that can be recorded and have implicit meaning.

The Three-Schema Architecture

The three-schema architecture aims to separate user applications from the physical database.

  1. Internal Level (Internal Schema)

    • Describes the physical storage structure of the database.
    • Uses a physical data model, detailing data storage and access paths.
    A3+vtlIur9G4AAAAAElFTkSuQmCC
  2. Conceptual Level (Conceptual Schema)

    • Describes the entire database structure for all
Read More

Python Code Examples: Data Structures, Algorithms, and More

Python Code Examples

Game2048

This code implements the game 2048, including functions for moving cells, checking for blocked states, and managing the game board.

def __can_move_cell__(self, row, col):
    value = self.cells[row][col]
    if value == 0:
        found_mov = True
    else:
        found_mov = False
        i = 0
        pos_lst = [(-1,0),(1,0),(0,-1),(0,1)]
        while i < len(pos_lst) and not found_mov:
            row_i = row + pos_lst[i][0]
            col_i = col + pos_lst[i]
Read More

Understanding Number Systems: Types, Concepts, and Applications

Number Systems

A number system is a way of representing numbers using digits or symbols. It consists of three components:

  1. Base (or Radix): The number of unique digits used in the system.
  2. Digits: The symbols used to represent numbers. For example, 0-9 in the decimal system.
  3. Place Value: The value assigned to each digit based on its position.

Types of Number Systems

  1. Binary (Base 2): Uses 2 digits, 0 and 1.
  2. Decimal (Base 10): Uses 10 digits, 0-9.
  3. Octal (Base 8): Uses 8 digits, 0-7.
  4. Hexadecimal (Base 16): Uses
Read More

Introduction to C Programming: Exam Questions & Solutions

Section A

  1. Attempt all questions. (Maximum word limit: 50)

    a. Why does a computer understand only binary language?

    Computers understand only binary language because they operate using electrical signals, which have two states: on (1) and off (0). These two states correspond to binary digits, making binary the most efficient and reliable way to represent data and instructions electronically.

    b. What are system software and application software? Give examples.

    • System software: This includes programs that
Read More

A Comprehensive Guide to Web Development Basics

Structure of XML

XML Data Representation

Example:

<?xml version="1.0" encoding="UTF-8"?>
<library>
  <book id="b1">
    <title>HP</title>
    <author>J.K. Rowling</author>
  </book>
  <book id="b2">
    <!-- Book details to be added -->
  </book>
</library>

DTD (Document Type Definition)

Definition: A set of rules that define the structure and legal elements of an XML document.

Internal DTD

Embedded within the XML document. Example:

Read More