How to resolve the algorithm Compare length of two strings step by step in the Lambdatalk programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Compare length of two strings step by step in the Lambdatalk programming language

Table of Contents

Problem Statement

Given two strings of different length, determine which string is longer or shorter. Print both strings and their length, one on each line. Print the longer one first. Measure the length of your string in terms of bytes or characters, as appropriate for your language. If your language doesn't have an operator for measuring the length of a string, note it. Given more than two strings: list = ["abcd","123456789","abcdef","1234567"] Show the strings in descending length order.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Compare length of two strings step by step in the Lambdatalk programming language

Source code in the lambdatalk programming language

{def L.new
 {lambda {:s}
  {if {S.empty? {S.rest :s}}
   then {P.new {S.first :s} nil}
   else {P.new {S.first :s} {L.new {S.rest :s}}}}}}
-> L.new 

{def L.disp
 {lambda {:l}
  {if {W.equal? :l nil}
   then 
   else {br} {W.length {P.left :l}} : {P.left :l}
        {L.disp {P.right :l}}}}}
-> L.disp


{def B {L.new abcd 123456789 abcdef 1234567}}
-> B

{L.disp {B}}
-> 
 4 : abcd 
 9 : 123456789 
 6 : abcdef 
 7 : 1234567


{def L.sort
 {lambda {:filter :l} 
  {if {W.equal? :l nil} 
   then nil 
   else {L.insert {P.left :l} :filter
                  {L.sort :filter {P.right :l}}}}}}
-> L.sort

{def L.insert
 {lambda {:x :filter :l} 
  {if {W.equal? :l nil} 
   then {P.new :x nil} 
   else {if {:filter :x {P.left :l}} 
   then {P.new :x :l} 
   else {P.new {P.left :l}
              {L.insert :x :filter {P.right :l}}}}}}}
-> L.insert


{def filter
 {lambda {:a :b}
  {> {W.length :a} {W.length :b}}}}
-> filter


{L.disp {L.sort filter {B}}}
-> 
 9 : 123456789 
 7 : 1234567 
 6 : abcdef 
 4 : abcd


  

You may also check:How to resolve the algorithm Zeckendorf number representation step by step in the 360 Assembly programming language
You may also check:How to resolve the algorithm Number reversal game step by step in the J programming language
You may also check:How to resolve the algorithm Priority queue step by step in the Lua programming language
You may also check:How to resolve the algorithm Roots of a function step by step in the Phix programming language
You may also check:How to resolve the algorithm Sort three variables step by step in the JavaScript programming language