• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
coding trails

coding trails

hello wisconsin!!!

  • Cards of Power

Archives for October 2024

Paradigm Shift

October 10, 2024 by schildawg Leave a Comment

In order to keep things simple while covering the basics, up till now I’ve written as if there is a single mathematical model governing the relationship of all words to each other.  This is certainly not the case.  There are potential models for every person in the world.  For every philosophy, every religion, and every viewpoint.  There are even valid models for every combination and permutation of every existing model.  If a single model is a universe, the set of all models is the multiverse!

In upcoming posts I will explore how different models can interact with each other, merging or clashing.  Models are also not static, but are continuously changing.  However, in this post we will look at how even using the same training data can result in different models.

Let’s say we have two models, one with 1,000 dimensions, and another with 150, and we train them both using the book War and Peace.  Both models will contain around 20,000 words.  But the model with fewer dimensions will be lower resolution, and the words will lack the nuances of the model with more dimensions.  If you reduce the resolution too much, the model becomes worthless, like a blurry picture where you can’t make out the details.

Because of diminishing returns, the 850 extra dimensions do not make the model 5 – 6 times more accurate.  But if you include or omit an important dimension, it can make a huge difference.  A perfect example of this is looking up into the night sky, and seeing two stars which appear to be right next to each other.  But because of their distances from earth (the dimension we can’t see) they might really be very far apart.

This is what is known as a “paradigm shift.”  A paradigm shift is when a single bit of information fundamentally changes your view of a concept or situation.  Similarly, in a model, a single dimension can fundamentally change the meaning of a word.

Let’s take for example the words “pepper” and “jalapeño.”  The two words are very similar, and share many dimensions, clustering them close together in the model with other vegetables and fruits.  But if you add the dimension “spiciness” they become much further apart.  Though not as far apart as “jalapeño” and “strawberry”.  

Without this dimension, the prompt “create a recipe for two alarm chili” might end up substituting “jalapeño” with “bell pepper”, resulting in some disappointing results!

 

Filed Under: AI

LeetCode

October 7, 2024 by schildawg Leave a Comment

Disclaimer:  I don’t believe LeetCode is a true judge of a software engineer’s ability in most cases, and do not endorse the use of it for interviewing.  My main purpose is to showcase Algol-24, while at the same time proving to myself that my language can handle all these scenarios.

Index:

  1. Two Sum – Easy
  2. Add Two Numbers – Medium
  3. Longest Substring Without Repeating Characters  – Medium
  4. Median of Two Sorted Arrays – In Progress – Hard

 

 

Filed Under: Uncategorized

Longest Substring Without Repeating Characters

October 7, 2024 by schildawg Leave a Comment

Description

Given a string s, find the length of the longest substring without repeating characters.

Tests

As always, let’s start out with the tests:

/// The answer is 'abc', with the length of 3.
///
test 'Example 1';
begin
    AssertEqual(3, LongestSubstring('abcabcbb'));
end

/// The answer is 'b', with the length of 1.
///
test 'Example 2';
begin
    AssertEqual(1, LongestSubstring('bbbbb'));
end

/// The answer is 'wke', with the length of 3. Notice that 
/// the answer must be a substring, 'pwke' is a subsequence 
/// and not a substring.
///
test 'Example 3';
begin
    AssertEqual(3, LongestSubstring('pwwkew'));
end

 

Solution

This is a medium level LeetCode question.  Coding it is simple if you know the concept of the “sliding window.”

function LongestSubstring(S : String) : Integer;
var
   Start, Finish, TheMax : Integer := 0;
   TheSet : Set := Set();

begin
    while Finish < Length(S) do
    begin
        if Not TheSet.Contains(S[Finish]) then
            begin
                TheSet.Add(S[Finish]);        
                Finish := Finish + 1;
                
                TheMax := Max(TheSet.Length, TheMax);
            end
        else
            begin
                TheSet.Remove(S[Start]);
                Start := Start + 1;
            end 
    end
    Exit TheMax;
end

Use a Set to keep track of the unique characters.  Start out with the “window” start and finish at the beginning of the String, and loop until the finish is at the end of the String.  If the character at the end of the window is not in the Set, add it and move the end by one.  If not, remove the character at the start of the window from the Set and move the start by one.

When the end of the window is at the end of window, return the largest number of characters the Set contained.  (Every time you add a character, set the max to the length of the Set, if it is larger than the previous max.

Filed Under: LeetCode, Programming

Primary Sidebar

Recent Posts

  • Modernization Code Converter
  • Paradigm Shift
  • LeetCode
  • Longest Substring Without Repeating Characters
  • The Big Bang
  • Add Two Numbers
  • The Word
  • Two Sum

Archives

  • June 2025
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • April 2024

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in

  • Cards of Power