How to resolve the algorithm Long literals, with continuations step by step in the Julia programming language

Published on 22 June 2024 08:30 PM

How to resolve the algorithm Long literals, with continuations step by step in the Julia programming language

Table of Contents

Problem Statement

This task is about writing a computer program that has long literals   (character literals that may require specifying the words/tokens on more than one (source) line,   either with continuations or some other method, such as abutments or concatenations   (or some other mechanisms).

The literal is to be in the form of a "list",   a literal that contains many words (tokens) separated by a blank (space),   in this case   (so as to have a common list),   the (English) names of the chemical elements of the periodic table.

The list is to be in (ascending) order of the (chemical) element's atomic number: ... up to the last known (named) chemical element   (at this time).

Do not include any of the   "unnamed"   chemical element names such as:

To make computer programming languages comparable,   the statement widths should be restricted to less than   81   bytes (characters),   or less if a computer programming language has more restrictive limitations or standards. Also mention what column the programming statements can start in if   not   in column one.

The list   may   have leading/embedded/trailing blanks during the declaration   (the actual program statements),   this is allow the list to be more readable.   The "final" list shouldn't have any leading/trailing or superfluous blanks   (when stored in the program's "memory"). This list should be written with the idea in mind that the program   will   be updated,   most likely someone other than the original author,   as there will be newer (discovered) elements of the periodic table being added   (possibly in the near future).   These future updates should be one of the primary concerns in writing these programs and it should be "easy" for someone else to add chemical elements to the list   (within the computer program). Attention should be paid so as to not exceed the   clause length   of continued or specified statements,   if there is such a restriction.   If the limit is greater than (say) 4,000 bytes or so,   it needn't be mentioned here.

Show all output here, on this page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Long literals, with continuations step by step in the Julia programming language

Julia Source Code Overview

The provided Julia code reads and processes a list of chemical elements, excluding certain elements specified in a separate list. It then prints information about the processed list.

Detailed Explanation

1. Constant Definitions:

  • CHEMICAL_ELEMENTS: A multiline string containing a list of chemical elements.
  • EXCLUDED: A list of strings containing elements that should be excluded from the processing.

2. process_chemical_element_list Function:

  • Removes leading and trailing whitespaces from the input string.
  • Splits the string using whitespace as a separator and returns a list of elements.
  • Excludes elements listed in EXCLUDED from the resulting list.

3. report Function:

  • Retrieves the modification time of the file containing the code using mtime.
  • Converts the unix timestamp to a formatted date and time using unix2datetime.
  • Calls process_chemical_element_list to process the list of chemical elements.
  • Counts the number of elements in the processed list.
  • Extracts the last element from the processed list.
  • Prints the file's last revision date and time, the length of the processed list, and the last element in the list.

4. Main Logic:

  • The report function is called to execute the processing and printing of information.

Usage:

This code can be used to generate a list of chemical elements after excluding a specified set of elements. It also provides information about the source file, including its last revision date and time.

Note:

This code demonstrates the use of Julia's string manipulation and list processing capabilities, as well as the ability to define custom functions and constants.

Source code in the julia programming language

using Dates

# FOR FUTURE EDITORS:
#
# Add to this list by adding more lines of text to this listing, placing the
# new words of text before the last """ below, with all entries separated by
# spaces.
#
const CHEMICAL_ELEMENTS = """

hydrogen helium lithium beryllium boron carbon nitrogen oxygen fluorine neon 
sodium magnesium aluminum silicon phosphorus sulfur chlorine argon potassium 
calcium scandium titanium vanadium chromium manganese iron cobalt nickel copper
zinc gallium germanium arsenic selenium bromine krypton rubidium strontium 
yttrium zirconium niobium molybdenum technetium ruthenium rhodium palladium 
silver cadmium indium tin antimony tellurium iodine xenon cesium barium 
lanthanum cerium praseodymium neodymium promethium samarium europium gadolinium
terbium dysprosium holmium erbium thulium ytterbium lutetium hafnium tantalum 
tungsten rhenium osmium iridium platinum gold mercury thallium lead bismuth 
polonium astatine radon francium radium actinium thorium protactinium uranium 
neptunium plutonium americium curium berkelium californium einsteinium fermium 
mendelevium nobelium lawrencium rutherfordium dubnium seaborgium bohrium hassium 
meitnerium darmstadtium roentgenium copernicium nihonium flerovium moscovium
livermorium tennessine oganesson

"""
#
# END OF ABOVE LISTING--DO NOT ADD ELEMENTS BELOW THIS LINE
#

const EXCLUDED = split(strip(
"ununennium unquadnilium triunhexium penthextrium penthexpentium " *
" septhexunium octenntrium ennennbium"), r"\s+")

function process_chemical_element_list(s = CHEMICAL_ELEMENTS)
    # remove leading and trailing whitespace
    s = strip(s)
    # return a list after splitting using whitespace between words as a separator
    return [element for element in split(s, r"\s+") if !(element in EXCLUDED)]
end

function report()
    filedate = Dates.unix2datetime(mtime(@__FILE__))
    element_list = process_chemical_element_list()
    element_count = length(element_list)
    last_element_in_list = element_list[end]
    
    println("File last revised (formatted as dateTtime): ", filedate, " GMT")
    println("Length of element list: ", element_count)
    println("last element in list: ", last_element_in_list)
end

report()


  

You may also check:How to resolve the algorithm MD5 step by step in the Ol programming language
You may also check:How to resolve the algorithm Active Directory/Connect step by step in the AutoIt programming language
You may also check:How to resolve the algorithm Calendar - for REAL programmers step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm ABC problem step by step in the Swift programming language
You may also check:How to resolve the algorithm Function definition step by step in the Pascal programming language