37
\$\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\$
  • 4
    \$\begingroup\$ Popplers taste great... Is that futurama reference :D \$\endgroup\$ – DJMcMayhem Dec 1 '16 at 4:44
  • 2
    \$\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 Dec 1 '16 at 7:50
  • 1
    \$\begingroup\$ Did a bit of jiggery pokery to get one showing. \$\endgroup\$ – Jonathan Allan Dec 1 '16 at 7:57
  • 9
    \$\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 Dec 1 '16 at 23:33
  • 4
    \$\begingroup\$ "basic scares goats" :/ I can confirm this is false \$\endgroup\$ – Downgoat Dec 3 '16 at 3:34
14
\$\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\$
  • 1
    \$\begingroup\$ Looks like we both need to find one more save now :) \$\endgroup\$ – Jonathan Allan Dec 1 '16 at 16:51
  • \$\begingroup\$ "." can be '. for 1 byte saved. \$\endgroup\$ – Emigna Dec 2 '16 at 12:39
  • 1
    \$\begingroup\$ Or A7£œJðý72ô€¨'.«9ô9£» for 20. \$\endgroup\$ – Emigna Dec 2 '16 at 12:46
  • \$\begingroup\$ Ouch. Fair dos!! \$\endgroup\$ – Jonathan Allan Dec 2 '16 at 14:24
27
\$\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\$
  • 2
    \$\begingroup\$ You can save bytes by using the first 7 characters of the alphabet abcdefg. \$\endgroup\$ – Magic Octopus Urn Dec 1 '16 at 15:41
  • 1
    \$\begingroup\$ Gahhh... That was the byte I could've beat you with too. I'm dumb haha. \$\endgroup\$ – Magic Octopus Urn Dec 1 '16 at 15:58
  • \$\begingroup\$ I have a feeling you'll get there anyway! \$\endgroup\$ – Jonathan Allan Dec 1 '16 at 16:05
  • 4
    \$\begingroup\$ Tag, you're it, find another byte ;). \$\endgroup\$ – Magic Octopus Urn Dec 1 '16 at 17:12
10
\$\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\$
  • \$\begingroup\$ Where does 102M come from? \$\endgroup\$ – Mukul Kumar Dec 1 '16 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 Dec 1 '16 at 23:27
8
\$\begingroup\$

Python 3, 121 119 bytes

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

repl.it

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\$
8
\$\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\$
  • \$\begingroup\$ I see car bus car bus in there \$\endgroup\$ – Destructible Lemon Dec 2 '16 at 0:23
  • \$\begingroup\$ Wait nvm just my display \$\endgroup\$ – Destructible Lemon Dec 2 '16 at 0:24
  • \$\begingroup\$ It would be shorter to just do Print@"fng cdaz vpi. pascal broke basic. popplers taste great." \$\endgroup\$ – Pavel Dec 2 '16 at 2:22
  • 1
    \$\begingroup\$ @Pavel Perfectly valid essay, but you're about 720 words shy of my homework assignment. \$\endgroup\$ – H Walters Dec 2 '16 at 4:51
  • \$\begingroup\$ @HWalters I see, I misread the problem. Oops. \$\endgroup\$ – Pavel Dec 2 '16 at 5:52
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\$
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\$
  • \$\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\$ – Jonathan Allan Dec 1 '16 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 Dec 1 '16 at 8:48
  • \$\begingroup\$ Can you save bytes by assigning range(9) to a variable, as well as & instead of .intersection? \$\endgroup\$ – Zacharý Dec 3 '16 at 21:55
  • \$\begingroup\$ Or by assigning a variable to range, then using that? \$\endgroup\$ – Zacharý Dec 3 '16 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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