2019-03-05 23:32:32 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
s "github.com/inancgumus/prettyslice"
|
|
|
|
)
|
|
|
|
|
2019-03-06 01:14:01 +03:00
|
|
|
//
|
|
|
|
// ! NOTE If the program does not work, please update your
|
|
|
|
// local copy of the prettyslice package:
|
|
|
|
//
|
|
|
|
// go get -u github.com/inancgumus/prettyslice
|
|
|
|
//
|
|
|
|
|
2019-03-05 23:32:32 +03:00
|
|
|
// ---------------------------------------------------------
|
|
|
|
// EXERCISE: Add newlines to the lyric sentences
|
|
|
|
//
|
|
|
|
// You have a slice of lyrics data of Beatles' awesome
|
|
|
|
// song: Yesterday. Your goal is adding newlines after
|
|
|
|
// each sentence of the lyric.
|
|
|
|
//
|
|
|
|
// Your goal is creating a new slice, then copying
|
|
|
|
// each sentence of the lyric to the new buffer, then
|
|
|
|
// after each sentence adding a newline character.
|
|
|
|
//
|
2019-03-05 23:49:54 +03:00
|
|
|
// You will get across something like this all the time
|
|
|
|
// in your gopher life. Believe me, learning how to
|
|
|
|
// solve this exercise will make you a better hopher.
|
2019-03-05 23:32:32 +03:00
|
|
|
//
|
|
|
|
//
|
|
|
|
// RESTRICTIONS
|
|
|
|
//
|
|
|
|
// . For warming-up, in this exercise, never use the `append()` func.
|
|
|
|
//
|
|
|
|
// . Instead, only use the `copy()` func.
|
|
|
|
//
|
2019-03-05 23:49:54 +03:00
|
|
|
// . Don't use slicing for printing the sentences.
|
2019-03-05 23:32:32 +03:00
|
|
|
//
|
2019-03-05 23:49:54 +03:00
|
|
|
// . Instead, use slicing for filling the new buffer.
|
2019-03-05 23:32:32 +03:00
|
|
|
//
|
|
|
|
//
|
|
|
|
// STEPS
|
|
|
|
//
|
2019-03-05 23:49:54 +03:00
|
|
|
// . Please follow the instructions inside the code.
|
2019-03-05 23:32:32 +03:00
|
|
|
//
|
|
|
|
//
|
|
|
|
// EXPECTED OUTPUT
|
|
|
|
//
|
|
|
|
// yesterday all my troubles seemed so far away
|
|
|
|
// now it looks as though they are here to stay
|
|
|
|
// oh i believe in yesterday
|
|
|
|
//
|
|
|
|
// ---------------------------------------------------------
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
//
|
|
|
|
// YOU DON'T NEED TO TOUCH THIS
|
|
|
|
//
|
|
|
|
// This inits some options for the prettyslice package.
|
|
|
|
// You can change the options if you want.
|
|
|
|
//
|
2019-03-05 23:49:54 +03:00
|
|
|
// s.Colors(false) // if your editor is light background color then enable this
|
2019-03-05 23:32:32 +03:00
|
|
|
s.PrintBacking = true // prints the backing arrays
|
|
|
|
s.MaxPerLine = 15 // prints max 15 elements per line
|
2019-03-25 14:07:23 +03:00
|
|
|
s.SpaceCharacter = '*' // print this instead of printing a newline (for debugging)
|
2019-03-05 23:32:32 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// UNCOMMENT THE VARIABLE BELOW THEN START!
|
|
|
|
//
|
|
|
|
|
|
|
|
// lyric := strings.Fields(`yesterday all my troubles seemed so far away now it looks as though they are here to stay oh i believe in yesterday`)
|
|
|
|
|
|
|
|
//
|
|
|
|
// RESTRICTION EXPLANATION:
|
|
|
|
//
|
2019-03-05 23:49:54 +03:00
|
|
|
// Do not use slicing for printing the sentences.
|
|
|
|
//
|
|
|
|
// For example, don't do something like this:
|
2019-03-05 23:32:32 +03:00
|
|
|
//
|
|
|
|
// fmt.Println(lyric[:8])
|
|
|
|
// fmt.Println(lyric[8:18])
|
|
|
|
// fmt.Println(lyric[18:23])
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
//
|
|
|
|
// #1: CREATE A LARGE ENOUGH BUFFER (A NEW SLICE)
|
|
|
|
//
|
2019-03-05 23:49:54 +03:00
|
|
|
// You need to put each lyric sentence
|
|
|
|
// + a newline character into this buffer
|
2019-03-05 23:32:32 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
// I name the buffer: `fix`, you can name it however you want
|
|
|
|
// fix := make(...)
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
//
|
|
|
|
// #2: CALCULATE THE CUT POINTS
|
|
|
|
//
|
|
|
|
// You want to put newlines after each sentence. So you may want to put
|
|
|
|
// these index positions into a slice. Then you can use them to cut the
|
|
|
|
// lyric slice.
|
|
|
|
//
|
|
|
|
|
|
|
|
// cutpoints := []int{...}
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
//
|
|
|
|
// #3: CREATE A LOOP AND COPY THE SENTENCES INTO THE BUFFER
|
|
|
|
//
|
|
|
|
|
|
|
|
// for ... {
|
|
|
|
// Use the `copy` function to copy from the `lyric` slice to the buffer.
|
|
|
|
//
|
|
|
|
// Copy a newline character (in a string) to the buffer after each sentence.
|
|
|
|
//
|
|
|
|
// You can use slicing here for filling the new buffer.
|
|
|
|
//
|
|
|
|
// Uncomment this to aid debugging (to see how the fix slice changes)
|
|
|
|
// s.Show("fix slice", fix)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
//
|
|
|
|
// #4: PRINT THE BUFFER
|
|
|
|
//
|
|
|
|
|
|
|
|
// ...
|
|
|
|
}
|