Skip to main content
3 of 7
deleted 2144 characters in body
Nick Kennedy
  • 21.2k
  • 3
  • 17
  • 43

Jelly, 80 bytes

ḢfØDV‘2ị=”JƲ}¡o1
ɠ⁻⁶x8¤$пYœṣ”¶x5¤Ỵ€
Ḳ-ị¢Ḣw¥Ƈị@ÑKœṣḲṪ¹⁾1:;$f?”:Ʋ2ịwⱮØD;€”:¤œPƊḢḊ

Try it online!

A full program that takes the pg10.txt file via STDIN and the required biblical reference as its only argument. TIO fails with the full document (presumably because the POST exceeds the maximum size), and the links to TIO on CGCC are even more limited because of length. However, it should work with the full text if run locally.

Explanation

ḢfØDV‘2ị=”JƲ}¡o1                             # ‎⁡Helper link 1: Takes a bible reference and returns which number book should be used that matches the textual part of the reference; half the code is to handle the John letters
Ḣ                                            # ‎⁢Head
 fØD                                         # ‎⁣Keep only digits
    V                                        # ‎⁤Evaluate (will be 0 if no digits)
      2ị=”JƲ}¡                               # ‎⁢⁡If the second remaining character is a J:
     ‘                                       # ‎⁢⁢- Increment by 1
              o1                             # ‎⁢⁣Or 1 (replaces 0s with ones)
‎⁢⁤
ɠ⁻⁶x8¤$пYœṣ”¶x5¤Ỵ€                          # ‎⁣⁡Helper link 2: Called niladically, reads the bible from STDIN and splits up into books
ɠ     $п                                    # ‎⁣⁢Read lines from STDIN until the following is false:
 ⁻⁶x8¤                                       # ‎⁣⁣- The read line is not equal to eight spaces
         Y                                   # ‎⁣⁤Join with newlines
          œṣ”¶x5¤                            # ‎⁤⁡Split at five consecutive newlines
                 Ỵ€                          # ‎⁤⁢Split each book at newlines
‎⁤⁣
Ḳ-ị¢Ḣw¥Ƈị@ÑKœṣḲṪ¹⁾1:;$f?”:Ʋ2ịwⱮØD;€”:¤œPƊḢḊ  # ‎⁤⁤Main link: takes a bible reference as its argument and returns the verse
Ḳ                                            # ‎⁢⁡⁡Split at spaces
 -ị                                          # ‎⁢⁡⁢Penultimate part (will be the last word of the book title)
   ¢Ḣw¥Ƈ                                     # ‎⁢⁡⁣Keep those books (from helper link 2) where the first line contains this as a sublist
        ị@Ñ                                  # ‎⁢⁡⁤Index into this using the result of calling helper link 1 on the original reference (so returning a single book)
           K                                 # ‎⁢⁢⁡Join at spaces
            œṣ            Ʋ                  # ‎⁢⁢⁢Split at the substring determined by calling following on the original reference:
              Ḳ                              # ‎⁢⁢⁣- Split at spaces
               Ṫ                             # ‎⁢⁢⁤- Tail (i.e. the verse or chapter:verse)
                      f?”:                   # ‎⁢⁣⁡- If contains a colon:
                ¹                            # ‎⁢⁣⁢  - Leave as is
                 ⁾1:;$                       # ‎⁢⁣⁣  - Else: prepend "1:"
                           2ị                # ‎⁢⁣⁤Take the second part (i.e. the bit immediately after the chapter:verse reference)
                                        Ɗ    # ‎⁢⁤⁡Following as a monad:
                             wⱮØD;€”:¤       # - ‎⁢⁤⁡Find the position of every sublist that comprises of a digit followed by a colon
                                      œP     # ‎⁢⁤⁡- And split at these
                                         ḢḊ  # ‎⁢⁤⁢Take the first remaining part, and then remove the first character (which will be the space left just after the original chapter:verse marker)
💎

Created with the help of Luminespire.

Nick Kennedy
  • 21.2k
  • 3
  • 17
  • 43