Saturday, December 7, 2024

 Problem statement: Given a wire grid of size N * N with N-1 horizontal edges and N-1 vertical edges along the X and Y axis respectively, and a wire burning out every instant as per the given order using three matrices A, B, C such that the wire that burns is  

(A[T], B[T] + 1), if C[T] = 0 or 
(A[T] + 1, B[T]), if C[T] = 1 

Determine the instant after which the circuit is broken  

     public static boolean checkConnections(int[] h, int[] v, int N) { 

        boolean[][] visited = new boolean[N][N]; 

        dfs(h, v, visited,0,0); 

        return visited[N-1][N-1]; 

    } 

    public static void dfs(int[]h, int[]v, boolean[][] visited, int i, int j) { 

        int N = visited.length; 

        if (i < N && j < N && i>= 0 && j >= 0 && !visited[i][j]) { 

            visited[i][j] = true; 

            if (v[i * (N-1) + j] == 1) { 

                dfs(h, v, visited, i, j+1); 

            } 

            if (h[i * (N-1) + j] == 1) { 

                dfs(h, v, visited, i+1, j); 

            } 

            if (i > 0 && h[(i-1)*(N-1) + j] == 1) { 

                dfs(h,v, visited, i-1, j); 

            } 

            if (j > 0 && h[(i * (N-1) + (j-1))] == 1) { 

                dfs(h,v, visited, i, j-1); 

            } 

        } 

    } 

    public static int burnout(int N, int[] A, int[] B, int[] C) { 

        int[] h = new int[N*N]; 

        int[] v = new int[N*N]; 

        for (int i = 0; i < N*N; i++) { h[i] = 1; v[i] = 1; } 

        for (int i = 0; i < N; i++) { 

            h[(i * (N)) + N - 1] = 0; 

            v[(N-1) * (N) + i] = 0; 

        } 

        System.out.println(printArray(h)); 

        System.out.println(printArray(v)); 

        for (int i = 0; i < A.length; i++) { 

            if (C[i] == 0) { 

                v[A[i] * (N-1) + B[i]] = 0; 

            } else { 

                h[A[i] * (N-1) + B[i]] = 0; 

            } 

            if (!checkConnections(h,v, N)) { 

                return i+1; 

            } 

        } 

        return -1; 

    } 

        int[] A = new int[9]; 

        int[] B = new int[9]; 

        int[] C = new int[9]; 

        A[0] = 0;    B [0] = 0;    C[0] = 0; 

        A[1] = 1;    B [1] = 1;    C[1] = 1; 

        A[2] = 1;    B [2] = 1;    C[2] = 0; 

        A[3] = 2;    B [3] = 1;    C[3] = 0; 

        A[4] = 3;    B [4] = 2;    C[4] = 0; 

        A[5] = 2;    B [5] = 2;    C[5] = 1; 

        A[6] = 1;    B [6] = 3;    C[6] = 1; 

        A[7] = 0;    B [7] = 1;    C[7] = 0; 

        A[8] = 0;    B [8] = 0;    C[8] = 1; 

        System.out.println(burnout(9, A, B, C)); 

1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0  

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0  

8 
Alternatively, 

    public static boolean burnWiresAtT(int N, int[] A, int[] B, int[] C, int t) { 

        int[] h = new int[N*N]; 

        int[] v = new int[N*N]; 

        for (int i = 0; i < N*N; i++) { h[i] = 1; v[i] = 1; } 

        for (int i = 0; i < N; i++) { 

            h[(i * (N)) + N - 1] = 0; 

            v[(N-1) * (N) + i] = 0; 

        } 

        System.out.println(printArray(h)); 

        System.out.println(printArray(v)); 

        for (int i = 0; i < t; i++) { 

            if (C[i] == 0) { 

                v[A[i] * (N-1) + B[i]] = 0; 

            } else { 

                h[A[i] * (N-1) + B[i]] = 0; 

            } 

        } 

        return checkConnections(h, v, N); 

    } 

    public static int binarySearch(int N, int[] A, int[] B, int[] C, int start, int end) { 

        if (start == end) { 

            if (!burnWiresAtT(N, A, B, C, end)){ 

                return end; 

            } 

            return  -1; 

        } else { 

            int mid = (start + end)/2; 

            if (burnWiresAtT(N, A, B, C, mid)) { 

                return binarySearch(N, A, B, C, mid + 1, end); 

            } else { 

                return binarySearch(N, A, B, C, start, mid); 

            } 

        } 

    } 

1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0  

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0  

8 
 

Friday, December 6, 2024

 This is a summary of the book titled “the art and science of facilitation” written and published by Marsha Acker in 2021. She says collaboration is a necessity of the modern workplace and facilitating that is both an art and a science. Her practical framework taps the collective intelligence . People don’t collaborate well for various reasons, but the facilitator can draw out an objective natural perspective rather engages everyone. They must embrace conflict and persevere. They should trust and honor the teams knowledge and insight. Facilitators must recognize they are responsible for being Agile and starting processes. They make organizations realize the desired change with communication.

Facilitation is an essential skill in today's fast-paced business world that helps teams access their collective intelligence and make authentic, creative decisions. Facilitators lead teams towards common goals and must be agile to adapt to and accommodate change. They help create innovative, high-performing teams by drawing on self-awareness, self-management, group awareness, and group process. Collaboration helps employees work cooperatively, be innovative, and productive, and enjoy fulfilling their responsibilities. Facilitation corrects this problem by allowing bottom-up decision-making and giving employees greater individual independence in pursuing shared goals. It is often undervalued in leadership competencies, but skilled facilitation is crucial for achieving clear goals in an atmosphere of mutual respect. Without facilitators, group collaboration can become chaotic and frustrating.

Facilitators play a crucial role in fostering a collaborative spirit within a team by providing an objective, neutral perspective. They are not a team member but an outsider, promoting a process where every member can participate and contribute their views. Neutral facilitators resist sharing their opinions, fostering trust and confidence among team members. They focus on the process rather than the content, allowing them to see from a wider perspective.

Facilitators must embrace conflict and persevere, allowing team members to articulate multiple points of view. They must remain present and engaged, observing the unfolding conflict to gain a better understanding of the team's social dynamics.

Facilitators should also trust and honor the team's knowledge and insight. They must acknowledge that each member possesses wisdom worth sharing and that everyone can receive wisdom from others. This acknowledgement of collective wisdom is essential, as it helps the team reach solutions and strengthens the group.

The facilitator must trust and honor the team's knowledge and insight, as teams are dynamic entities with their own dynamics. Honoring the collective wisdom of the group is crucial, as it involves acknowledging each member's worth sharing and allowing everyone to receive wisdom from others. Facilitators must sustain the belief that the team has the wisdom needed to reach solutions, which strengthens the group. Focusing on the group's vision and agenda is also important, as it keeps the team's needs at the forefront. Groups have three levels of agendas: the presenting agenda, the emergent agenda, and the developmental agenda. Facilitators should follow through with these levels, as they can provide momentum for meaningful change on the team and corporate levels. However, young, or inexperienced facilitators should understand that they retain the prerogative to say no, as not every facilitator will be on board with every agenda or goal.

Facilitators must be agile and maintain a neutral mindset, embracing conflict and team members' insights. They should work with a co-facilitator to learn and expand their practice. Maintaining personal notebooks and asking probing questions can help keep work organized and prevent stagnation. Facilitators should understand why adopting an agile mindset is productive for their teams and how to embody agility in practice. They should identify the best way to maintain agility and manage processes, not finding solutions or delivering results.

Mastery of facilitation requires deep inner resources, including wisdom and courage. Facilitators must deal with conflict and opposition, guiding their teams to success. They should be clear on their model and grounded in their practice. Facilitation ultimately rests on enabling collaboration and self-awareness. They should find collective wisdom, talk about what matters, and bring the conversation into the room. The principles behind facilitating team collaboration open the door to exploring the use and potential of dialogue, which is central to the issues teams and organizations face.


Thursday, December 5, 2024

 CodingExercise: Rotate List

Medium

Topics

Companies

Given the head of a linked list, rotate the list to the right by k places.

Example 1:

Input: head = [1,2,3,4,5], k = 2

Output: [4,5,1,2,3]

Example 2:

Input: head = [0,1,2], k = 4

Output: [2,0,1]

Constraints:

The number of nodes in the list is in the range [0, 500].

-100 <= Node.val <= 100

0 <= k <= 2 * 109

/**

 * Definition for singly-linked list.

 * public class ListNode {

 * int val;

 * ListNode next;

 * ListNode() {}

 * ListNode(int val) { this.val = val; }

 * ListNode(int val, ListNode next) { this.val = val; this.next = next; }

 * }

 */

class Solution {

    public ListNode rotateRight(ListNode head, int k) {

        if (head == null || k == 0) return head;

        Listhead current = head;

        int n = 0;

        while (current){

             n++;

             current = current.next;

        }

        if (k > n) { k = k % n;}

        int offset = n - k;

        current = head;

        if (offset > 0) {

            while (offset > 1) {

                current = current.next;

                offset--;

            }

            ListNode remaining = current.next;

            current.next = null;

            ListHead end = remaning;

            while (end && end.next) {

                end = end.next;

            }

            end.next = head;

            return remaining;

        }

        return head;

    }

}


Wednesday, December 4, 2024

 Mesh networking and UAV (Unmanned Aerial Vehicle) swarm flight communication share several commonalities, particularly in how they handle connectivity and data transfer: 

 

Dynamic Topology: Both systems often operate in environments where the network topology can change dynamically. In mesh networks, nodes can join or leave the network, and in UAV swarms, drones can move in and out of range. 

 

Self-Healing: Mesh networks are designed to automatically reroute data if a node fails or a connection is lost. Similarly, UAV swarms use mesh networking to maintain communication even if some drones drop out or move out of range. 

 

Redundancy: Both systems use redundancy to ensure reliable communication. In mesh networks, multiple paths can be used to send data, while in UAV swarms, multiple drones can relay information to ensure it reaches its destination. 

 

Decentralization: Mesh networks are decentralized, meaning there is no single point of failure. UAV swarms also benefit from decentralized communication, allowing them to operate independently and collaboratively without relying on a central control point. 

 

Scalability: Both mesh networks and UAV swarms can scale to accommodate more nodes or drones, respectively, without significant degradation in performance. 

 

These commonalities make mesh networking an ideal solution for UAV swarm communication, ensuring robust and reliable connectivity even in challenging environments. 

Similarly, distributed hash tables, cachepoints arranged in a ring and consensus algorithms also play part in the communications between drones. 

Cachepoints are used with consistent hashing. They are arranged along the circle depicting the key range and cache objects corresponding to the range. Virtual nodes can join and leave the network without impacting the operation of the ring. 

Data is partitioned and replicated using consistent hashing to achieve scale and availability. Consistency is facilitated by object versioning. Replicas are maintained during updates based on a quorum like technique. 

In a distributed environment, the best way to detect failures and determine memberships is with the help of gossip protocol. When an existing node leaves the network, it may not respond to the gossip protocol so the neighbors become aware.  The neighbors update the membership changes and copy data asynchronously. 

Some systems utilize a state machine replication such as Paxos that combines transaction logging  for consensus with write-ahead logging for data recovery. If the state machines are replicated, they are fully Byzantine tolerant. 

Monday, December 2, 2024

 This is a summary of the book titled “Technology’s Child: Digital Media’s Role in the Ages and Stages of growing up” written by Katie Davis and published by MIT Press in 2023. This book is about the impact of digital technology on a child’s development. She examines how technology influences social connections, mental health, and identity formation revealing both the upsides and downsides. She highlights the need for thoughtful design, policy changes, and parental guidance to create healthier digital experiences. Parental guidance and control can determine the right use of an interactive technology and the development of the executive functions of the child but that said, self-paced learning and social interaction are also important. Balancing digital and real-world play is equally important. Social media and smartphones create both challenges and opportunities and play up to teens vulnerabilities but can also foster creativity and community. A lot of stakeholders must come together to design developmentally supportive technology.

Interactive technology can support the development of executive functions in children if children control their engagement with it and parents’ guide its use. The rise of interactive digital media, such as games on tablets and smartphones, can both support and hinder child development. However, apps that do not allow children to control the pace and steps of the game or activity can undermine these skills. Parents should be mindful of their children's technology use, opting for age-appropriate content and setting rules that limit screen time. Balancing screen time with active play and being conscious of how technology integrates into daily life is essential for healthy child development.

Digital tools play a crucial role in children's development by allowing self-paced learning and social interaction. Picture books and educational apps can help children explore themed objects, actions, and letters, while educational apps can encourage play and reward learning. Parents can provide personalized support for early literacy development by joining in with their children's tech experiences. The design of digital technology also plays a role in its effectiveness, with fast-paced or overly stimulating features hindering learning. Balancing digital and analog play is essential for fostering creativity, self-direction, and social skills. Open-ended and child-directed play is generally best, especially in early childhood. However, digital play may limit creativity compared to analog play, which encourages self-directed exploration. Parents should balance analog and digital play by allowing children to explore the natural world, ensuring that digital play doesn't dominate or detract from hands-on, creative experiences.

Digital technology has the potential to transform middle childhood learning by offering interactive and interest-driven opportunities. However, many schools fail to harness this potential, often using technology to replicate existing classroom practices. To overcome this, schools and educators should gradually change their learning and teaching processes and be open to new technologies. Collaboration with teachers, peers, and family members is crucial for promoting constructive digital learning. Social media and smartphones have transformed the relationship between tweens and parents, creating both challenges and opportunities. Parents view smartphones as safety tools, while tweens see them as symbols of freedom and autonomy. Social media can also introduce risks, such as connection overload and cyberbullying. Open dialogue between parents, teachers, and tweens is essential to improve these dynamics. Supportive interventions, such as teaching tweens how to manage digital stress, mute notifications, and reframe their online experiences, can help reduce the adverse effects of social media while promoting healthier peer interactions.

Social media platforms can exploit teen vulnerabilities and enhance their social interactions, causing negative self-comparison and depression. However, technology can also enrich adolescents' lives by providing avenues for self-expression and community. Teens use platforms like TikTok, Instagram, and Snapchat to explore and share creative content, form meaningful social bonds, and resist pressures of social comparison. Emerging adults can use networked technologies to engage in public discourse but can also cause participation anxiety. Social media activism can lead to emotional strain, harassment, and content exploitation, leading to burnout.

To support children's development, designers must focus on creating tools that allow flexibility, self-direction, and meaningful engagement. Collaboration with experts in child development and diverse communities is crucial to ensure equitable experiences for children of all social, cultural, and economic backgrounds. Policymakers should introduce regulations that incentivize tech companies to prioritize child well-being, such as the UK's Age-Appropriate Design Code.


Sunday, December 1, 2024

 The following implementation follows up on an article about contextual embeddings for UAV swarm camera image analytics.

import the

from azure.ai.vision import VisionClient, AzureKeyCredential, AnalyzeImageOptions

from azure.ai.textanalytics import TextAnalyticsClient

from langchain.embeddings import OpenAIEmbeddings

from langchain.text_splitter import RecursiveCharacterTextSplitter

from langchain.vectorstores import FAISS

# Replace with your Azure credentials and endpoints

vision_key = "YOUR_VISION_API_KEY"

vision_endpoint = "YOUR_VISION_API_ENDPOINT"

text_analytics_key = "YOUR_TEXT_ANALYTICS_API_KEY"

text_analytics_endpoint = "YOUR_TEXT_ANALYTICS_API_ENDPOINT"

# Initialize Azure Vision and Text Analytics clients

vision_client = VisionClient(credential=AzureKeyCredential(vision_key), endpoint=vision_endpoint)

text_analytics_client = TextAnalyticsClient(endpoint=text_analytics_endpoint, credential=AzureKeyCredential(text_analytics_key))

# Function to analyze image and extract tags and metadata

def extract_tags_and_metadata(image_url):

    analyze_options = AnalyzeImageOptions(features=["objects", "tags", "description"])

    analysis_result = vision_client.analyze_image(image_url, analyze_options)

    tags = [tag.name for tag in analysis_result.tags]

    metadata = {

        "description": analysis_result.description.captions[0].text if analysis_result.description.captions else "",

        "tags": tags

    }

    return metadata

# Function to generate a description using tags and metadata

def generate_description(tags, metadata):

    description = metadata["description"]

    if not description:

        description = f"This image contains {', '.join(tags)}."

    return description

# Example image collection

image_collection = [

    "URL_OF_IMAGE_1",

    "URL_OF_IMAGE_2",

    "URL_OF_IMAGE_3"

]

# Extract tags, metadata, and generate descriptions

image_data = []

for image_url in image_collection:

    metadata = extract_tags_and_metadata(image_url)

    description = generate_description(metadata["tags"], metadata)

    image_data.append({

        "url": image_url,

        "description": description

    })

# Function to match a query to the best description using text embeddings

def match_query_to_best_description(query, image_data):

    texts = [item["description"] for item in image_data]

    embedding = OpenAIEmbeddings()

    text_splitter = RecursiveCharacterTextSplitter()

    vectorstore = FAISS.from_texts(texts, embedding, text_splitter)

    query_embedding = embedding.embed_query(query)

    best_match = vectorstore.similarity_search(query_embedding, 1)

    return best_match[0]["page_content"] if best_match else None

# Example query

query = "A scenic view of mountains with a lake in the foreground"

# Find the best matching description for the query

best_description = match_query_to_best_description(query, image_data)

print("Best Matching Description:")

print(best_description)

#codingexercise: CodingExercise-12-01-2024.docx