42
\$\begingroup\$

My homework is to write a Martian essay (see below) between 729 and 810 words, inclusive. Your task is to write a program that will generate the essay.

History

Around the turn of the 20th century, spiritualist Catherine-Elise Müller allegedly communicated with Martians. During somnambulatory trances, she would write out Martian scripts. Psychologist Théodore Flourney discovered her Martian writings were very similar to her native French, and in his book "From India to the Planet Mars", he documented Catherine's Martian alphabet.

The following is loosely based on that alphabet with an extended mythos.

Problem Description

The Martian language has 21 letters, shown here next to each Latin equivalent:

enter image description here

Unfortunately, there's no Unicode for Martian (despite Mars being part of the universe), so we're stuck using Latin characters.

Whereas in English our phonemes break out into two major types (consonants/vowels) which we loosely map to letters, Martian has three letter types:

  • The vowels: a e i m n o u
  • The hard consonants: b c d g k p t
  • The soft consonants: f h l r s v z

In addition to this, the Martian language contains a single punctuation mark--the period.

A Martian word is a set of 3 to 9 letters. All Martian words have at least one vowel, one hard consonant, and one soft consonant (in any arrangement). For example, fng, cdaz, vpi, and pascal are Martian words.

A Martian sentence is a set of 3 to 9 Martian words delimited by spaces and followed by a period.

A Martian paragraph is a set of 3 to 9 Martian sentences delimited by spaces and followed by a newline.

A Martian essay is a collection of Martian paragraphs that contains no contiguous word repetitions.

A contiguous word repetition is any construct S S where S is a contiguous set of words. Note that this definition ignores sentence and paragraph boundaries.

Examples

Please note: There's a single trailing newline following each example (since all Martian paragraphs end in a newline)

Not Martian essay

lorem ipsum dolor sit amet. quis nostrud exercitation ullamco laboris.

...for many reasons. This example is to illustrate some miscellaneous rules:

  • lorem is not a Martian word because it has no hard consonants.
  • amet is not a Martian word because it has no soft consonants. (m is a Martian vowel).
  • quis is not a Martian word because it has no hard consonants
  • quis is not a Martian word because q is not a Martian letter
  • exercitation is not a Martian word because it has more than 9 letters
  • exercitation is not a Martian word because x is not a Martian letter

Martian essay

fng cdaz vpi. pascal broke basic. popplers taste great.

...because it is a Martian paragraph. The Martian paragraph contains three Martian sentences.

Not Martian essay

fng cdaz vpi. pascal broke basic. free pascal rules.

...since free pascal rules. is not a Martian sentence, because neither free nor rules are Martian words, because they do not have any hard consonants.

Martian essay

fng cdaz vpi. pascal broke basic. popplers taste great.
cdaz vpi fng. basic breaks pascal. popplers punch hard. fng cdaz vpi.

...which contains two Martian paragraphs. The sentence fng cdaz vpi. appears twice, but that's perfectly fine.

Not Martian essay

popplers taste fng. cdaz vpi pascal. broke fng cdaz vpi.
pascal broke omicron planets. basic scares goats. vpi piv vpi.

...because the construct fng. cdaz vpi pascal. broke fng cdaz vpi. [nl] pascal broke is a contiguous word repetition.

Challenge

Your challenge is to write a function or program that accepts no input, which produces as its output my homework; that is, your program should generate a Martian essay between 729 and 810 words (inclusive). Keep in mind, your program's output must be a valid Martian essay, but you don't have to generate it randomly or different each time. Anything you do to generate a valid Martian essay counts.

I've written a C++ program to check essays that you're allowed to use.

This is code golf. Shortest code in bytes wins. Standard loopholes disallowed.

\$\endgroup\$
16
  • 4
    \$\begingroup\$ Popplers taste great... Is that futurama reference :D \$\endgroup\$
    – DJMcMayhem
    Commented Dec 1, 2016 at 4:44
  • 3
    \$\begingroup\$ Also, though I answered DrMcMoylex in chat, just for the record here... yes. (FYI, the 729 and 810 word requirement, which is 1000 to 1100 words in base 9, is also an indirect reference) \$\endgroup\$
    – H Walters
    Commented Dec 1, 2016 at 7:50
  • 1
    \$\begingroup\$ Did a bit of jiggery pokery to get one showing. \$\endgroup\$ Commented Dec 1, 2016 at 7:57
  • 13
    \$\begingroup\$ I think this is the first time I've seen a "Do my homework for me" question on codegolf. Usually those are on stackoverflow proper. :-) \$\endgroup\$
    – Ray
    Commented Dec 1, 2016 at 23:33
  • 4
    \$\begingroup\$ "basic scares goats" :/ I can confirm this is false \$\endgroup\$
    – Downgoat
    Commented Dec 3, 2016 at 3:34

13 Answers 13

30
\$\begingroup\$

Jelly, 28 26 25 24 23 bytes

-1 byte thanks to carusocomputing (replace the word thimble with abcdefg)

9ØaḣŒ!s²ḣµs9K€;€”.K;⁷µ€

TryItOnline!

How?

Makes a list of all 362880 permutations of the first seven nine letters of the English alphabet abcdefghi, which all have the properties of Martian words and are all distinct, and formats them into an essay using the first 729 words.

9ØaḣŒ!s²ḣµs9K€;€”.K;⁷µ€ - Main link: no arguments
9                       - 9 as x
         µ              - monadic chain separation
 Øa                     - yield lowercase alphabet
   ḣ                    - head to x ("abcdefghi")
    Œ!                  - all permutations (362880 distinct Martian words)
       ²                - square x = 81 
      s                 - split into chunks of length 81 (the paragraphs)
        ḣ               - head to x (get the first 9 paragraphs only)
                     µ€ - monadic chain for €ach (for each chunk:)
          s9            -     split into chunks of length 9 (the sentences)
            K€          -     join with spaces for €each (between words in each sentence)
              ;€        -     concatenate €ach with
                ”.      -         '.' (add a full stop* after each sentence)
                  K     -     join with spaces (add a space between the sentences)
                   ;    -     concatenate with
                    ⁷   -         a line feed
                        - implicit print

* period

\$\endgroup\$
4
  • 2
    \$\begingroup\$ You can save bytes by using the first 7 characters of the alphabet abcdefg. \$\endgroup\$ Commented Dec 1, 2016 at 15:41
  • 1
    \$\begingroup\$ Gahhh... That was the byte I could've beat you with too. I'm dumb haha. \$\endgroup\$ Commented Dec 1, 2016 at 15:58
  • \$\begingroup\$ I have a feeling you'll get there anyway! \$\endgroup\$ Commented Dec 1, 2016 at 16:05
  • 5
    \$\begingroup\$ Tag, you're it, find another byte ;). \$\endgroup\$ Commented Dec 1, 2016 at 17:12
19
\$\begingroup\$

05AB1E, 25 24 22 20 bytes

-2 bytes thanks to Emigna (Significant refactor, thanks man).

A7£œJðý72ô€¨'.«9ô9£»

Try it online!

A7£                     # Push first 7 letters of the alphabet.
   œJðý                 # All 5040 permutations of "abcdefg" joined by spaces.
       72ô              # Split into pieces of 72 (Sentences).
          €             # For each piece...
           ¨'.«         # Lop of the last char and concat a period.
               9ô       # Split into pieces of 9 (paragraphs).
                 9£     # Take only the first 9 paragraphs.
                   »    # Join by newlines and implicitly print.

Turns out the 810 word version is shorter than the 729 word version.

Output:

abcdefg abcdegf abcdfeg abcdfge abcdgef abcdgfe abcedfg abcedgf abcefdg. abcefgd abcegdf abcegfd abcfdeg abcfdge abcfedg abcfegd abcfgde abcfged. abcgdef abcgdfe abcgedf abcgefd abcgfde abcgfed abdcefg abdcegf abdcfeg. abdcfge abdcgef abdcgfe abdecfg abdecgf abdefcg abdefgc abdegcf abdegfc. abdfceg abdfcge abdfecg abdfegc abdfgce abdfgec abdgcef abdgcfe abdgecf. abdgefc abdgfce abdgfec abecdfg abecdgf abecfdg abecfgd abecgdf abecgfd. abedcfg abedcgf abedfcg abedfgc abedgcf abedgfc abefcdg abefcgd abefdcg. abefdgc abefgcd abefgdc abegcdf abegcfd abegdcf abegdfc abegfcd abegfdc. abfcdeg abfcdge abfcedg abfcegd abfcgde abfcged abfdceg abfdcge abfdecg.
abfdegc abfdgce abfdgec abfecdg abfecgd abfedcg abfedgc abfegcd abfegdc. abfgcde abfgced abfgdce abfgdec abfgecd abfgedc abgcdef abgcdfe abgcedf. abgcefd abgcfde abgcfed abgdcef abgdcfe abgdecf abgdefc abgdfce abgdfec. abgecdf abgecfd abgedcf abgedfc abgefcd abgefdc abgfcde abgfced abgfdce. abgfdec abgfecd abgfedc acbdefg acbdegf acbdfeg acbdfge acbdgef acbdgfe. acbedfg acbedgf acbefdg acbefgd acbegdf acbegfd acbfdeg acbfdge acbfedg. acbfegd acbfgde acbfged acbgdef acbgdfe acbgedf acbgefd acbgfde acbgfed. acdbefg acdbegf acdbfeg acdbfge acdbgef acdbgfe acdebfg acdebgf acdefbg. acdefgb acdegbf acdegfb acdfbeg acdfbge acdfebg acdfegb acdfgbe acdfgeb.
acdgbef acdgbfe acdgebf acdgefb acdgfbe acdgfeb acebdfg acebdgf acebfdg. acebfgd acebgdf acebgfd acedbfg acedbgf acedfbg acedfgb acedgbf acedgfb. acefbdg acefbgd acefdbg acefdgb acefgbd acefgdb acegbdf acegbfd acegdbf. acegdfb acegfbd acegfdb acfbdeg acfbdge acfbedg acfbegd acfbgde acfbged. acfdbeg acfdbge acfdebg acfdegb acfdgbe acfdgeb acfebdg acfebgd acfedbg. acfedgb acfegbd acfegdb acfgbde acfgbed acfgdbe acfgdeb acfgebd acfgedb. acgbdef acgbdfe acgbedf acgbefd acgbfde acgbfed acgdbef acgdbfe acgdebf. acgdefb acgdfbe acgdfeb acgebdf acgebfd acgedbf acgedfb acgefbd acgefdb. acgfbde acgfbed acgfdbe acgfdeb acgfebd acgfedb adbcefg adbcegf adbcfeg.
adbcfge adbcgef adbcgfe adbecfg adbecgf adbefcg adbefgc adbegcf adbegfc. adbfceg adbfcge adbfecg adbfegc adbfgce adbfgec adbgcef adbgcfe adbgecf. adbgefc adbgfce adbgfec adcbefg adcbegf adcbfeg adcbfge adcbgef adcbgfe. adcebfg adcebgf adcefbg adcefgb adcegbf adcegfb adcfbeg adcfbge adcfebg. adcfegb adcfgbe adcfgeb adcgbef adcgbfe adcgebf adcgefb adcgfbe adcgfeb. adebcfg adebcgf adebfcg adebfgc adebgcf adebgfc adecbfg adecbgf adecfbg. adecfgb adecgbf adecgfb adefbcg adefbgc adefcbg adefcgb adefgbc adefgcb. adegbcf adegbfc adegcbf adegcfb adegfbc adegfcb adfbceg adfbcge adfbecg. adfbegc adfbgce adfbgec adfcbeg adfcbge adfcebg adfcegb adfcgbe adfcgeb.
adfebcg adfebgc adfecbg adfecgb adfegbc adfegcb adfgbce adfgbec adfgcbe. adfgceb adfgebc adfgecb adgbcef adgbcfe adgbecf adgbefc adgbfce adgbfec. adgcbef adgcbfe adgcebf adgcefb adgcfbe adgcfeb adgebcf adgebfc adgecbf. adgecfb adgefbc adgefcb adgfbce adgfbec adgfcbe adgfceb adgfebc adgfecb. aebcdfg aebcdgf aebcfdg aebcfgd aebcgdf aebcgfd aebdcfg aebdcgf aebdfcg. aebdfgc aebdgcf aebdgfc aebfcdg aebfcgd aebfdcg aebfdgc aebfgcd aebfgdc. aebgcdf aebgcfd aebgdcf aebgdfc aebgfcd aebgfdc aecbdfg aecbdgf aecbfdg. aecbfgd aecbgdf aecbgfd aecdbfg aecdbgf aecdfbg aecdfgb aecdgbf aecdgfb. aecfbdg aecfbgd aecfdbg aecfdgb aecfgbd aecfgdb aecgbdf aecgbfd aecgdbf.
aecgdfb aecgfbd aecgfdb aedbcfg aedbcgf aedbfcg aedbfgc aedbgcf aedbgfc. aedcbfg aedcbgf aedcfbg aedcfgb aedcgbf aedcgfb aedfbcg aedfbgc aedfcbg. aedfcgb aedfgbc aedfgcb aedgbcf aedgbfc aedgcbf aedgcfb aedgfbc aedgfcb. aefbcdg aefbcgd aefbdcg aefbdgc aefbgcd aefbgdc aefcbdg aefcbgd aefcdbg. aefcdgb aefcgbd aefcgdb aefdbcg aefdbgc aefdcbg aefdcgb aefdgbc aefdgcb. aefgbcd aefgbdc aefgcbd aefgcdb aefgdbc aefgdcb aegbcdf aegbcfd aegbdcf. aegbdfc aegbfcd aegbfdc aegcbdf aegcbfd aegcdbf aegcdfb aegcfbd aegcfdb. aegdbcf aegdbfc aegdcbf aegdcfb aegdfbc aegdfcb aegfbcd aegfbdc aegfcbd. aegfcdb aegfdbc aegfdcb afbcdeg afbcdge afbcedg afbcegd afbcgde afbcged.
afbdceg afbdcge afbdecg afbdegc afbdgce afbdgec afbecdg afbecgd afbedcg. afbedgc afbegcd afbegdc afbgcde afbgced afbgdce afbgdec afbgecd afbgedc. afcbdeg afcbdge afcbedg afcbegd afcbgde afcbged afcdbeg afcdbge afcdebg. afcdegb afcdgbe afcdgeb afcebdg afcebgd afcedbg afcedgb afcegbd afcegdb. afcgbde afcgbed afcgdbe afcgdeb afcgebd afcgedb afdbceg afdbcge afdbecg. afdbegc afdbgce afdbgec afdcbeg afdcbge afdcebg afdcegb afdcgbe afdcgeb. afdebcg afdebgc afdecbg afdecgb afdegbc afdegcb afdgbce afdgbec afdgcbe. afdgceb afdgebc afdgecb afebcdg afebcgd afebdcg afebdgc afebgcd afebgdc. afecbdg afecbgd afecdbg afecdgb afecgbd afecgdb afedbcg afedbgc afedcbg.
afedcgb afedgbc afedgcb afegbcd afegbdc afegcbd afegcdb afegdbc afegdcb. afgbcde afgbced afgbdce afgbdec afgbecd afgbedc afgcbde afgcbed afgcdbe. afgcdeb afgcebd afgcedb afgdbce afgdbec afgdcbe afgdceb afgdebc afgdecb. afgebcd afgebdc afgecbd afgecdb afgedbc afgedcb agbcdef agbcdfe agbcedf. agbcefd agbcfde agbcfed agbdcef agbdcfe agbdecf agbdefc agbdfce agbdfec. agbecdf agbecfd agbedcf agbedfc agbefcd agbefdc agbfcde agbfced agbfdce. agbfdec agbfecd agbfedc agcbdef agcbdfe agcbedf agcbefd agcbfde agcbfed. agcdbef agcdbfe agcdebf agcdefb agcdfbe agcdfeb agcebdf agcebfd agcedbf. agcedfb agcefbd agcefdb agcfbde agcfbed agcfdbe agcfdeb agcfebd agcfedb.
agdbcef agdbcfe agdbecf agdbefc agdbfce agdbfec agdcbef agdcbfe agdcebf. agdcefb agdcfbe agdcfeb agdebcf agdebfc agdecbf agdecfb agdefbc agdefcb. agdfbce agdfbec agdfcbe agdfceb agdfebc agdfecb agebcdf agebcfd agebdcf. agebdfc agebfcd agebfdc agecbdf agecbfd agecdbf agecdfb agecfbd agecfdb. agedbcf agedbfc agedcbf agedcfb agedfbc agedfcb agefbcd agefbdc agefcbd. agefcdb agefdbc agefdcb agfbcde agfbced agfbdce agfbdec agfbecd agfbedc. agfcbde agfcbed agfcdbe agfcdeb agfcebd agfcedb agfdbce agfdbec agfdcbe. agfdceb agfdebc agfdecb agfebcd agfebdc agfecbd agfecdb agfedbc agfedcb. bacdefg bacdegf bacdfeg bacdfge bacdgef bacdgfe bacedfg bacedgf bacefdg.
\$\endgroup\$
5
  • 1
    \$\begingroup\$ Looks like we both need to find one more save now :) \$\endgroup\$ Commented Dec 1, 2016 at 16:51
  • \$\begingroup\$ "." can be '. for 1 byte saved. \$\endgroup\$
    – Emigna
    Commented Dec 2, 2016 at 12:39
  • 1
    \$\begingroup\$ Or A7£œJðý72ô€¨'.«9ô9£» for 20. \$\endgroup\$
    – Emigna
    Commented Dec 2, 2016 at 12:46
  • \$\begingroup\$ Ouch. Fair dos!! \$\endgroup\$ Commented Dec 2, 2016 at 14:24
  • 1
    \$\begingroup\$ The J isn't necessary anymore (I assume the permutations builtin resulted in a list of lists before?). In addition, the ðý72ô€¨ can be golfed to 9ôðý: 16 bytes \$\endgroup\$ Commented Oct 30, 2020 at 9:00
11
\$\begingroup\$

Ruby, 86 83 82 79 bytes

(8019..8747).map{|x|$><<x.to_s(3).tr('012','abf')+(x%9>7?".\n":x%3>1?". ":" ")}

The trick: print all numbers between 102000000 and 102222222 in base 3

\$\endgroup\$
2
  • \$\begingroup\$ Where does 102M come from? \$\endgroup\$ Commented Dec 1, 2016 at 17:06
  • \$\begingroup\$ The numbers between 102000000 and 102222222 (base 3) become 9-letter words. 8019 base 10 is 102M base 3. \$\endgroup\$
    – G B
    Commented Dec 1, 2016 at 23:27
9
\$\begingroup\$

Mathematica, 113 bytes

StringRiffle[(p=Partition)["ark"["bus","car"][[#]]&/@Differences@Array[ThueMorse,730],3]~p~3,n=".\n",". "," "]<>n

Unnamed function that produces a string as output; that string is a Martian essay where each sentence has three words and each paragraph has three sentences. (Its deterministic output is below.)

The core of the algorithm uses the cool mathematical fact that the differences of the Thue–Morse sequence form an infinite sequence of the three symbols –1, 0, and 1 that has no contiguous digit repetitions. Differences@Array[ThueMorse,730] generates that sequence, to length 729.

Then "ark"["bus","car"][[#]]&/@ is applied to this sequence; this converts each 1 to "bus" (the first argument), each –1 to "car" (the last argument), and each 0 to "ark" (the function head). (p=Partition)[...,3]~p~3 divides this sequence of words into nested lists, each consisting of three lists of three words each. Finally, StringRiffle[...,n=".\n",". "," "] concatenates all the words together, with different separators depending on the list levels; and <>n appends the final period and newline.

The output sure doesn't look repetition-free....

ark car bus. car ark bus. ark car ark.
bus car bus. ark car bus. car ark bus.
car bus ark. car ark bus. ark car bus.
car ark bus. ark car ark. bus car bus.
ark car ark. bus ark car. bus car ark.
bus car bus. ark car bus. car ark bus.
ark car ark. bus car bus. ark car bus.
car ark bus. car bus ark. car ark bus.
ark car bus. car ark bus. car bus ark.
car bus car. ark bus ark. car ark bus.
car bus ark. car ark bus. ark car bus.
car ark bus. ark car ark. bus car bus.
ark car bus. car ark bus. car bus ark.
car ark bus. ark car bus. car ark bus.
ark car ark. bus car bus. ark car ark.
bus ark car. bus car ark. bus car bus.
ark car bus. car ark bus. ark car ark.
bus car bus. ark car ark. bus ark car.
bus car ark. bus ark car. ark bus car.
bus ark car. bus car ark. bus car bus.
ark car ark. bus ark car. bus car ark.
bus car bus. ark car bus. car ark bus.
ark car ark. bus car bus. ark car bus.
car ark bus. car bus ark. car ark bus.
ark car bus. car ark bus. ark car ark.
bus car bus. ark car ark. bus ark car.
bus car ark. bus car bus. ark car bus.
car ark bus. ark car ark. bus car bus.
ark car bus. car ark bus. car bus ark.
car ark bus. ark car bus. car ark bus.
car bus ark. car bus car. ark bus ark.
car ark bus. car bus ark. car ark bus.
ark car bus. car ark bus. ark car ark.
bus car bus. ark car bus. car ark bus.
car bus ark. car ark bus. ark car bus.
car ark bus. car bus ark. car bus car.
ark bus ark. car ark bus. car bus ark.
car bus car. ark bus car. bus ark car.
ark bus ark. car bus car. ark bus ark.
car ark bus. car bus ark. car ark bus.
ark car bus. car ark bus. car bus ark.
car bus car. ark bus ark. car ark bus.
car bus ark. car ark bus. ark car bus.
car ark bus. ark car ark. bus car bus.
ark car bus. car ark bus. car bus ark.
car ark bus. ark car bus. car ark bus.
ark car ark. bus car bus. ark car ark.
bus ark car. bus car ark. bus car bus.
ark car bus. car ark bus. ark car ark.
bus car bus. ark car bus. car ark bus.
car bus ark. car ark bus. ark car bus.
car ark bus. car bus ark. car bus car.
ark bus ark. car ark bus. car bus ark.
car ark bus. ark car bus. car ark bus.
ark car ark. bus car bus. ark car bus.
car ark bus. car bus ark. car ark bus.
ark car bus. car ark bus. ark car ark.
bus car bus. ark car ark. bus ark car.
bus car ark. bus car bus. ark car bus.
car ark bus. ark car ark. bus car bus.
ark car ark. bus ark car. bus car ark.
bus ark car. ark bus car. bus ark car.
bus car ark. bus car bus. ark car ark.
bus ark car. bus car ark. bus car bus.
ark car bus. car ark bus. ark car ark.
bus car bus. ark car bus. car ark bus.
car bus ark. car ark bus. ark car bus.
car ark bus. ark car ark. bus car bus.
ark car ark. bus ark car. bus car ark.
bus car bus. ark car bus. car ark bus.
ark car ark. bus car bus. ark car ark.
bus ark car. bus car ark. bus ark car.
ark bus car. bus ark car. bus car ark.
bus car bus. ark car ark. bus ark car.
bus car ark. bus ark car. ark bus car.
bus ark car. ark bus ark. car bus car.
ark bus car. bus ark car. bus car ark.
bus ark car. ark bus car. bus ark car.
bus car ark. bus car bus. ark car ark.
bus ark car. bus car ark. bus car bus.
ark car bus. car ark bus. ark car ark.

Mathematica, 100 bytes

StringRiffle[(p=Partition)[Permutations@Characters@"thimble"~Take~729,9]~p~9,n=".\n",". "," ",""]<>n

A direct port of Jonathan Allen's Jelly algorithm.

\$\endgroup\$
5
  • \$\begingroup\$ I see car bus car bus in there \$\endgroup\$ Commented Dec 2, 2016 at 0:23
  • \$\begingroup\$ Wait nvm just my display \$\endgroup\$ Commented Dec 2, 2016 at 0:24
  • \$\begingroup\$ It would be shorter to just do Print@"fng cdaz vpi. pascal broke basic. popplers taste great." \$\endgroup\$
    – Pavel
    Commented Dec 2, 2016 at 2:22
  • 2
    \$\begingroup\$ @Pavel Perfectly valid essay, but you're about 720 words shy of my homework assignment. \$\endgroup\$
    – H Walters
    Commented Dec 2, 2016 at 4:51
  • \$\begingroup\$ @HWalters I see, I misread the problem. Oops. \$\endgroup\$
    – Pavel
    Commented Dec 2, 2016 at 5:52
9
\$\begingroup\$

Python 3, 121 119 114 bytes

-5 thanks to Jitse!

from itertools import*
i=729
while i:i-=1;print(*[*permutations('thimble')][i],sep='',end='.'[i%9:]+' \n'[i%81<1])

Try it online!

How?

Counts down from i=729 and gets a list of the letters of the ith permutation of 'thimble' as the next distinct Martian word (list(permutations('thimble'))[i]).

Avoids ''.join(...) by use of a *expression to unpack the list while changing the default separator for print from a space to the empty string (sep='').

Uses the end argument of print to optionally add spaces, full stops and line feeds as required using modular arithmetic. A full stop goes after every ninth word ('.'*(i%9<1)) and a line feed goes after every eighty-first word, otherwise a space does, achieved by indexing into a two character string (' \n'[i%81<1]).

\$\endgroup\$
2
  • \$\begingroup\$ 114 bytes \$\endgroup\$
    – Jitse
    Commented Oct 30, 2020 at 11:32
  • \$\begingroup\$ Thanks for that @Jitse \$\endgroup\$ Commented Oct 30, 2020 at 19:00
4
\$\begingroup\$

PHP, 86 bytes

for(;$i<729;$$s="")echo${$s=str_shuffle(abcdefg)}??$s.(++$i%3?"":".").($i%9?" ":"\n");

Generates a randomised 729 word essay that repeats no words.
Use like:

php -r 'for(;$i<729;$$s="")echo${$s=str_shuffle(abcdefg)}??$s.(++$i%3?"":".").($i%9?" ":"\n");'

Explanation:

for(;$i<729;                                      # until we've generated 729 words
  $$s="")                                         # assign a blank string to the variable for the previous word
    echo ${$s=str_shuffle(abcdefg)}??             # generate a random word and if the variable for it has been assigned echo that variable (a blank string)
         $s.(++$i%3?"":".").($i%9?" ":"\n");      # otherwise echo the string and punctuation based on the word number (which is incremented here)
\$\endgroup\$
2
  • \$\begingroup\$ newline counts as one byte, so it´s 85 not 86. Amazing golf! \$\endgroup\$
    – Titus
    Commented Oct 30, 2020 at 13:05
  • \$\begingroup\$ for($i=729;;$$ss="")...(--$i%3...)... should work as well and avoid a notice/warning. \$\endgroup\$
    – Titus
    Commented Oct 30, 2020 at 13:05
4
\$\begingroup\$

///, 95 bytes

/_/abf//-/_ _a _e _i _m _n _o _u _aa.//'/- b- c- d- g- j- p- t- bb-/'
f'
h'
l'
r'
s'
v'
z'
ff'

(additional new line at the end, not visible here)

Try it online!

Essay:

abf abfa abfe abfi abfm abfn abfo abfu abfaa. babf abfa abfe abfi abfm abfn abfo abfu abfaa. cabf abfa abfe abfi abfm abfn abfo abfu abfaa. dabf abfa abfe abfi abfm abfn abfo abfu abfaa. gabf abfa abfe abfi abfm abfn abfo abfu abfaa. jabf abfa abfe abfi abfm abfn abfo abfu abfaa. pabf abfa abfe abfi abfm abfn abfo abfu abfaa. tabf abfa abfe abfi abfm abfn abfo abfu abfaa. bbabf abfa abfe abfi abfm abfn abfo abfu abfaa.
fabf abfa abfe abfi abfm abfn abfo abfu abfaa. babf abfa abfe abfi abfm abfn abfo abfu abfaa. cabf abfa abfe abfi abfm abfn abfo abfu abfaa. dabf abfa abfe abfi abfm abfn abfo abfu abfaa. gabf abfa abfe abfi abfm abfn abfo abfu abfaa. jabf abfa abfe abfi abfm abfn abfo abfu abfaa. pabf abfa abfe abfi abfm abfn abfo abfu abfaa. tabf abfa abfe abfi abfm abfn abfo abfu abfaa. bbabf abfa abfe abfi abfm abfn abfo abfu abfaa.
habf abfa abfe abfi abfm abfn abfo abfu abfaa. babf abfa abfe abfi abfm abfn abfo abfu abfaa. cabf abfa abfe abfi abfm abfn abfo abfu abfaa. dabf abfa abfe abfi abfm abfn abfo abfu abfaa. gabf abfa abfe abfi abfm abfn abfo abfu abfaa. jabf abfa abfe abfi abfm abfn abfo abfu abfaa. pabf abfa abfe abfi abfm abfn abfo abfu abfaa. tabf abfa abfe abfi abfm abfn abfo abfu abfaa. bbabf abfa abfe abfi abfm abfn abfo abfu abfaa.
labf abfa abfe abfi abfm abfn abfo abfu abfaa. babf abfa abfe abfi abfm abfn abfo abfu abfaa. cabf abfa abfe abfi abfm abfn abfo abfu abfaa. dabf abfa abfe abfi abfm abfn abfo abfu abfaa. gabf abfa abfe abfi abfm abfn abfo abfu abfaa. jabf abfa abfe abfi abfm abfn abfo abfu abfaa. pabf abfa abfe abfi abfm abfn abfo abfu abfaa. tabf abfa abfe abfi abfm abfn abfo abfu abfaa. bbabf abfa abfe abfi abfm abfn abfo abfu abfaa.
rabf abfa abfe abfi abfm abfn abfo abfu abfaa. babf abfa abfe abfi abfm abfn abfo abfu abfaa. cabf abfa abfe abfi abfm abfn abfo abfu abfaa. dabf abfa abfe abfi abfm abfn abfo abfu abfaa. gabf abfa abfe abfi abfm abfn abfo abfu abfaa. jabf abfa abfe abfi abfm abfn abfo abfu abfaa. pabf abfa abfe abfi abfm abfn abfo abfu abfaa. tabf abfa abfe abfi abfm abfn abfo abfu abfaa. bbabf abfa abfe abfi abfm abfn abfo abfu abfaa.
sabf abfa abfe abfi abfm abfn abfo abfu abfaa. babf abfa abfe abfi abfm abfn abfo abfu abfaa. cabf abfa abfe abfi abfm abfn abfo abfu abfaa. dabf abfa abfe abfi abfm abfn abfo abfu abfaa. gabf abfa abfe abfi abfm abfn abfo abfu abfaa. jabf abfa abfe abfi abfm abfn abfo abfu abfaa. pabf abfa abfe abfi abfm abfn abfo abfu abfaa. tabf abfa abfe abfi abfm abfn abfo abfu abfaa. bbabf abfa abfe abfi abfm abfn abfo abfu abfaa.
vabf abfa abfe abfi abfm abfn abfo abfu abfaa. babf abfa abfe abfi abfm abfn abfo abfu abfaa. cabf abfa abfe abfi abfm abfn abfo abfu abfaa. dabf abfa abfe abfi abfm abfn abfo abfu abfaa. gabf abfa abfe abfi abfm abfn abfo abfu abfaa. jabf abfa abfe abfi abfm abfn abfo abfu abfaa. pabf abfa abfe abfi abfm abfn abfo abfu abfaa. tabf abfa abfe abfi abfm abfn abfo abfu abfaa. bbabf abfa abfe abfi abfm abfn abfo abfu abfaa.
zabf abfa abfe abfi abfm abfn abfo abfu abfaa. babf abfa abfe abfi abfm abfn abfo abfu abfaa. cabf abfa abfe abfi abfm abfn abfo abfu abfaa. dabf abfa abfe abfi abfm abfn abfo abfu abfaa. gabf abfa abfe abfi abfm abfn abfo abfu abfaa. jabf abfa abfe abfi abfm abfn abfo abfu abfaa. pabf abfa abfe abfi abfm abfn abfo abfu abfaa. tabf abfa abfe abfi abfm abfn abfo abfu abfaa. bbabf abfa abfe abfi abfm abfn abfo abfu abfaa.
ffabf abfa abfe abfi abfm abfn abfo abfu abfaa. babf abfa abfe abfi abfm abfn abfo abfu abfaa. cabf abfa abfe abfi abfm abfn abfo abfu abfaa. dabf abfa abfe abfi abfm abfn abfo abfu abfaa. gabf abfa abfe abfi abfm abfn abfo abfu abfaa. jabf abfa abfe abfi abfm abfn abfo abfu abfaa. pabf abfa abfe abfi abfm abfn abfo abfu abfaa. tabf abfa abfe abfi abfm abfn abfo abfu abfaa. bbabf abfa abfe abfi abfm abfn abfo abfu abfaa.
\$\endgroup\$
4
\$\begingroup\$

JavaScript (ES6), 130 bytes

This essay contains 774 Martian words, from a dictionary of 308 distinct words, made of all Martian letters.

_=>[...Array(2322)].map((_,i)=>['aeimnou','bcdgkpt','fhlrsvz'][i%3][(z=z*71%1e9)%7]+(++i%3?'':i%9?' ':i%27?'. ':`.
`),z=1).join``

Letters are picked in a pseudo-random manner, using the following formula:

(71^n mod 1000000000) mod 7

Where 71 is the smallest prime [1] for which no contiguous word repetition appear with this modulo.

let f =

_=>[...Array(2322)].map((_,i)=>['aeimnou','bcdgkpt','fhlrsvz'][i%3][(z=z*71%1e9)%7]+(++i%3?'':i%9?' ':i%27?'. ':`.
`),z=1).join``

console.log(f());


[1] I only tested primes at the time I wrote this code. The smallest non-prime candidate is 56.

\$\endgroup\$
3
\$\begingroup\$

Python 3, 404 270 332 339 285 266 259 bytes

This is an attempt to create a random Martian essay my randomly sampling the Martian alphabet and checking afterwards which words work.

Edit: -10 bytes from Zachary T's suggestion to use R=range. -9 bytes from changing .intersection(w) to &set(w). -7 bytes from changing A[random.randrange(21)] to random.choice(A).

import random
W=[];A="abfechidlmgrnksopvutz";R=range
while len(W)<729:W+=[''.join(random.choice(A)for j in R(9))for i in R(729)];W=[*set(w for w in W if all(set(A[z::3])&set(w)for z in R(3)))]
for j in R(9):print(" ".join(W[81*j+i]+"."*(i%9>7)for i in R(81)))

Ungolfing

import random
word_list = []
alphabet = "abfechidlmgrnksopvutz"
while len(word_list) < 729:
    # generates words
    for i in range(729):
        word = ""
        for j in range(9):
            word += alphabet[random.randrange(21)]
        word_list.append(word)
    # removes invalid words that don't have at least one letter of each letter type
    kept_words = []
    for word in word_list:
        all_letter_types = [0, 0, 0]
        for z in range(3):
            all_letter_types[z] = set(alphabet[z::3]) & set(word)
        if all(all_letter_types):
            kept_words.append(word)
    word_list = kept_words[:]
    # removes any contiguous word repetitions by removing all repeated words
    word_list = list(set(word_list))
# attaches punctuation and prints
for j in range(9):
    result = []
    for i in range(81):
        word = word_list[81*j+i]
        if i%9 == 8:
            word += "."
    print(" ".join(result))
\$\endgroup\$
4
  • \$\begingroup\$ You don't need the overhead of a function since there is no input it could just be the content of a file (i.e. a module). You don't need to make it random (although if you do want to use the module you'll need an import) \$\endgroup\$ Commented Dec 1, 2016 at 8:39
  • 1
    \$\begingroup\$ @JonathanAllan I knew I forgot something. Thanks for the heads up. I wanted to try a random answer anyway. EDIT: Oddly enough, adding the import and removing the indentation levels of the function overhead cancel each other out. Strange. \$\endgroup\$
    – Sherlock9
    Commented Dec 1, 2016 at 8:48
  • \$\begingroup\$ Can you save bytes by assigning range(9) to a variable, as well as & instead of .intersection? \$\endgroup\$
    – Adalynn
    Commented Dec 3, 2016 at 21:55
  • \$\begingroup\$ Or by assigning a variable to range, then using that? \$\endgroup\$
    – Adalynn
    Commented Dec 3, 2016 at 22:03
2
\$\begingroup\$

Husk, 19 18 bytes

↑9C9mo`:'.wC9P…"ag

Try it online!

729 words, using the same idea as the 05AB1E answer.

-1 byte from Dominic Van Essen.

\$\endgroup\$
3
  • \$\begingroup\$ Very nice, and seems to currently be the winner! I thought (based on the spec) you could even get 17 bytes using J, but the C++ checker doesn't seem to like having a space between the last word of each sentence and the full-stop. \$\endgroup\$ Commented Oct 30, 2020 at 9:33
  • \$\begingroup\$ 18 bytes using as rangeS. \$\endgroup\$ Commented Oct 30, 2020 at 9:42
  • \$\begingroup\$ @DominicvanEssen That saves some bytes in my other answers as well.. \$\endgroup\$
    – Razetime
    Commented Oct 30, 2020 at 9:54
2
\$\begingroup\$

Zsh -P, 51 bytes

x=(a e i m n o u)
echo $x{f,h,l,r,s}$x{b,d,g.}|fold

Attempt This Online!

The output has some trailing spaces, which I think are normally allowed, but if not, this can be fixed by adding |cut -c-79 (+10 bytes).

Explanation

The basic idea is to generate a number of unique Martian words, then group them into sentences and paragraphs.

I used 4-letter words of the format vsvh (vowel, soft consonant, vowel, hard consonant), because it makes it possible to get enough words using just one cartesian product. (This is what the {,,,} expansions do; the -P option to Zsh also enables that multiplying behaviour for array variables, allowing us to reuse $x).

There are enough unique 3-letter words to meet the word count, but they would require multiple separate expansions - one single format (e.g. vsh) can only produce \$ 7^3 = 343 \$ words. This would take too many extra bytes.

Then, by adding a . to one of the letters, we can ensure there are regular sentence breaks - here, it's every time g comes around in the cartesian product.

Finally, piping this all to fold inserts line breaks, to keep the paragraphs under 10 sentences each.

The fact that this all works, and can be so short, is slightly miraculous. It relies on some very specific mathematical properties: by having \$ x = 7 \$ vowels, \$ y = 5 \$ soft consonants, and \$ z = 3 \$ hard consonants, we ensure:

  • \$ 729 \le xyxz \le 810 \$, so our essay meets the word count
  • \$ z \ge 3 \$, so each sentence has enough words in it (remember one of the hard consonants has a . at the end)
  • \$ 80 \div (5z+1) \in \mathbb Z \cap [3, 9] \$, so the fold command, which defaults to wrapping every 80 characters, will break the essay up into paragraphs with a valid integer number of sentences
  • \$ xyxz \equiv 0 \mod (80 \div (5z+1))z \$, so the last paragraph doesn't have any remainder sentences

Any of the issues above could be worked around, of course, but that would cost extra bytes. \$ 7, 5, 3 \$ is actually the only choice that works perfectly!

\$\endgroup\$
1
\$\begingroup\$

K (ngn/k), 167 148 145 144 bytes

{("\n"/(" "/'(" "/''$(729>#,//){x,,(3+*1?7){l:3+*1?7;x,,`$(-#:'w)?'w:(,/'+l?'0 7 14_c),'(l?7)?\:c:"aeimnoubcdgkptfhlrsvz"}/()}/()),''".")),"\n"}

Try it online!

Stitches together a random character of each type, appending an additional 0-6 random characters to form words of length 3-9, which are then shuffled. Sentences are formed from 3-9 of these words, and paragraphs from 3-9 of those sentences.

Paragraphs are iteratively appended, with the essay being complete when it contains at least 729 words. Since a valid paragraph can only contain up to 81 words (9 words per sentence * 9 sentences), it's safe to write another paragraph as long as the essay contains less than 729 words.

However, proofreading the essay to ensure there is no contiguous word repetition is an exercise left to the reader.

{("\n"/                                /join each paragraph with a newline
  (" "/'                               /join sentences in a paragraph with a space
   (" "/''$                            /join words in a sentence with a space (converting words from symbols to strings)
    (729>#,//){                        /while the essay contains less than 729 words...
     x,,                                /append another paragraph of...
     (3+*1?7){                          /3 to 9 (randomly chosen) sentences each containing...
      l:3+*1?7;                         /3 to 9 (randomly chosen) words
      x,,`$                             /append the new sentence (casted to symbols), which is made of l words, each being a...
      (-#:'w)?'                         /randomly shuffled string of...
      w:(,/'+l?'0 7 14_c)               /a random character from each character type in the Martian alphabet
      ,'                                /concatenated with...
      (l?7)?\:c:"aeimnoubcdgkptfhlrsvz" /0 to 6 random characters from the Martian alphabet
     }/()
    }/()
   )
   ,''"."                               /finish each sentence with a period
  )
 )
 ,"\n"                                  /finish the essay with a newline
}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ -1: {729>#,//x} -> (729>#,//) \$\endgroup\$
    – ngn
    Commented Sep 8, 2021 at 3:23
0
\$\begingroup\$

CJam, 26 bytes

'h,97>e!".
"{9/Sf*Uf+}fU9<

Try it online!

First solution in a while where I've had to use a literal newline. Same idea as the 05AB1E answer.

sigh And if only concatenation was commutative...

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.