Longest Word in Mathematica

Published on 28 April 2022 (Updated: 02 February 2023)

Longest Word in Mathematica

Welcome to the Longest Word in Mathematica page! Here, you’ll find the source code for this program as well as a description of how the program works.

Current Solution

(* Code *)

(* Trivial: *)

longestWord = s \[Function] Max @@ StringLength /@ StringSplit[s];

(* The outer function provides the 'user interface' (e.g., the string parsing): *)

longestWordMain = Function[{s},
   Module[{e = "Usage: please provide a string"},
    Catch[
     longestWord @
      If[StringLength[s] > 0, s, Throw[e]]]]];


(* Valid Tests *)

Print /@ longestWord /@ {
    "May the force be with you",
    "Floccinaucinihilipilification",
    "Hi,\nMy name is Paul!"
    };


(* Invalid Tests *)

longestWordMain[""]

Longest Word in Mathematica was written by:

If you see anything you’d like to change or update, please consider contributing.

How to Implement the Solution

No ‘How to Implement the Solution’ section available. Please consider contributing.

How to Run the Solution

No ‘How to Run the Solution’ section available. Please consider contributing.