Longest Word in Mathematica

Published on 16 January 2023 (Updated: 16 January 2023)

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.