PK Creative Spring Festival, I am participating in the “Spring Festival Creative Submission Contest”, please see: Spring Festival Creative Submission Contest”

What is eight-part essay

Stereotyped Writing; Eight-legged Essay (also called system meaning, system arts, shi Wen, ba bi wen, is a style of imperial examination in Ming and Qing dynasties. Eight articles on the “four books and five Classics” topic, the content must use the tone of the ancients, absolutely not allowed to play freely, and the length of the sentence, the word complex and simple, the tone of the height and so on should be relatively written, the number of words are also limited. The eight-part essay refers to the eight parts of the article with a fixed style: it is composed of eight parts, namely, the thesis, the thesis, the beginning, the beginning, the middle, the last and the bundle. The topics are all from the original text of the four books and five Classics. The last four parts each have two pairs of antithesis text, a total of eight strands. In the old imperial examinations, the eight-part essay should be spoken in the tone of Confucius and Mencius. The four pairs of pairs were arranged in pairs, and the saints could not be blasphemed with allusions to romance, flowers, snow and moon. Each article included four parts from the beginning to the end. — Baidu Encyclopedia

Later, the eight-part essay was extended to mean “imprison thoughts” and “rigid and rigid”. What does it look like to write Spring Festival couplets in eight-part essay?

The common saying about Spring Festival couplets

  1. Oblique level, oblique level, oblique level.

  2. Day to the ground, rain to the wind, the mainland to the sky, thunder faint to foggy, open good luck to everything.

  3. Up against down, big against small, mountain flower against sea tree, red sun against sky.

There are, of course, many other rules, but this is a simple example. In this paper, the discussion is carried out with the minimum closed loop.

Let’s look at two relatively good Spring Festival couplets first.

Programming design

If simply follow the common rules to write Spring Festival couplets, many times it is not appropriate, this paper called this way of writing Spring Festival couplets “eight-part essay”. So, how to write Spring Festival couplets through programming simple eight-part essay? Let’s take a look.

1. Define two arrays

First, define two cross-reference arrays to store the words and terms of the above rules. The following uses Go as an example:

/ / this part
upArray := [...]string{"Day"."Rain"."The mainland"."On"."Big"."Mountain"."Red day"}
/ / bottom allied
blowArray := [...]string{"To"."The wind"."The sky"."Under"."Small"."The tree"."Sky"}
Copy the code

Notice that these two arrays can be very, very long, so let’s stop there.

2. Convert two Maps

According to the two arrays defined in the first step, the corresponding two maps are converted respectively. The two maps are defined with the element of the array as the key and the index value as the value. The relevant codes are as follows:

/ / this part
upMap := map[string]int{
        "Day": 0."Rain": 1."The mainland": 2."On": 3."Big": 4."Mountain": 5."Red day": 6."Autumn": 7,}/ / bottom allied
blowMap := map[string]int{
        "To": 0."The wind": 1."The sky": 2."Under": 3."Small": 4."The tree": 5."Sky": 6."Spring": 7,}Copy the code

3. Two ways to write Spring Festival couplets

The first way, automatically generate Spring Festival couplets

The way to automatically generate Spring Festival couplets is to automatically generate the upstream and downstream, coding implementation, need to rely on the two arrays mentioned above. The idea is to randomly generate a number, and then take the number of each number as the array index subscript, respectively through two arrays to generate the upstream and downstream. Give an example to see how to automatically generate Spring Festival couplets.

package main

import (
	"fmt"
	"math/rand"
        "time"
)

func main(a) {
	myRand := rand.New(rand.NewSource(time.Now().UnixNano()))
        // Random generated number
	n :=myRand.Intn(1000)
	fmt.Println(n)
}
Copy the code

The output is 235

The generated couplet code is as follows:

package main

import (
	"fmt"
)

func main(a) {
	// array
	upArray := [...]string{"Day"."Rain"."The mainland"."On"."Big"."Mountain"."Red day"}
	// concatenated array
	blowArray := [...]string{"To"."The wind"."The sky"."Under"."Small"."The tree"."Sky"}
	
	up := upArray[2]+upArray[3]+upArray[5]
	blow := blowArray[2]+blowArray[3]+blowArray[5]
	
	fmt.Println(up) // Mountain flowers on the mainland
	fmt.Println(blow) // Sea trees fall from the sky
}
Copy the code

So,

The first line is: mountain flowers on the mainland,

The next link is: the sky under the sea tree.

Evaluation: the statement is still neat, meaning, almost meaning.

The second way is based on the top to the bottom

This method is based on the existing line, automatically out of the next line. The code implementation relies on the two arrays and two maps mentioned above. According to the words and words in the preceding sentence, the corresponding array and index value index are obtained by traversing the two maps respectively, and the corresponding lower line is obtained by the corresponding array and index value index.

Let’s take a look at it through an example. If the top line is “spring breeze blowing sea trees”, the bottom line should be “autumn rain flowers on tianshan Mountain”. There seems to be a word missing, but if there are enough original fields, in fact, it can also be linked, may be the meaning of the meaning of almost meaning. The code implementation is as follows:

package main

import (
	"fmt"
)

func main(a) {
	// array
	upArray := [...]string{"Day"."Rain"."The mainland"."On"."Big"."Mountain"."Red day"."Autumn"}
   
	/ / bottom allied map
	blowMap := map[string]int{
		"To": 0."The wind": 1."The sky": 2."Under": 3."Small": 4."The tree": 5."Sky": 6."Spring":7 ,
	}
	one := []int{}
	one = append(one, blowMap["Spring"])
	one = append(one, blowMap["The wind"])
	one = append(one, blowMap["Blow"])
	one = append(one, blowMap["The tree"])
	res := ""
	for i:=0; i<len(one); i++ {
		res += upArray[one[i]]
	}
	
	fmt.Println(res)
}
Copy the code

conclusion

Ha ha, at present, it seems that the pure eight-part essay to write Spring Festival couplets is not very reliable, there are too many situations and artistic conception is difficult to blend in. Of course, we can also optimize the algorithm and improve the implementation method to make the program write more beautiful, more in line with human habits of Spring Festival couplets, such as the use of big data to collect enough materials, using artificial intelligence to simulate human habits and style “calculate” as beautiful as possible. Ok, so much for the discussion of writing Spring Festival couplets in eight-part essay. If you have any ideas, feel free to leave a comment! Finally, I wish you all a happy New Year and a happy Year of the Ox!


About the author: 😄 Hello everyone, MY name is Data-Mining (Liuzhen007). I am a typical audio and video technology enthusiast. I have worked for traditional broadcasting giants and audio and video Internet companies before and after, and I have rich experience in audio and video live broadcast and on-demand. Have a very deep understanding of WebRTC, FFmpeg and Electron, 😄 public account: Play with audio and video. Also CSDN blog expert, Huawei cloud sharing expert (co-create editor), InfoQ contract author, welcome to follow me to share more dry goods! 😄