diff --git a/23-project-log-parser/01-scanning/main.go b/23-input-scanning/01-scanning/main.go similarity index 100% rename from 23-project-log-parser/01-scanning/main.go rename to 23-input-scanning/01-scanning/main.go diff --git a/23-project-log-parser/01-scanning/proverbs.txt b/23-input-scanning/01-scanning/proverbs.txt similarity index 100% rename from 23-project-log-parser/01-scanning/proverbs.txt rename to 23-input-scanning/01-scanning/proverbs.txt diff --git a/23-input-scanning/02-map-as-sets/main.go b/23-input-scanning/02-map-as-sets/main.go new file mode 100644 index 0000000..53670de --- /dev/null +++ b/23-input-scanning/02-map-as-sets/main.go @@ -0,0 +1,44 @@ +package main + +// For more tutorials: https://blog.learngoprogramming.com +// +// Copyright © 2018 Inanc Gumus +// Learn Go Programming Course +// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ +// + +import ( + "bufio" + "fmt" + "os" +) + +func main() { + args := os.Args[1:] + if len(args) != 1 { + fmt.Println("Please type a search word.") + return + } + query := args[0] + + in := bufio.NewScanner(os.Stdin) + in.Split(bufio.ScanWords) + + // index the words + words := make(map[string]bool) + for in.Scan() { + words[in.Text()] = true + } + + // unnecessary + // if _, ok := words[query]; ok { + // ... + // } + + // answer the user query + if words[query] { + fmt.Printf("The input contains %q word.\n", query) + return + } + fmt.Printf("Sorry. The input does contain %q word.\n", query) +} diff --git a/23-project-log-parser/exercises/01-uppercaser/shakespeare.txt b/23-input-scanning/02-map-as-sets/shakespeare.txt similarity index 100% rename from 23-project-log-parser/exercises/01-uppercaser/shakespeare.txt rename to 23-input-scanning/02-map-as-sets/shakespeare.txt diff --git a/23-project-log-parser/02-project-log-parser/log.txt b/23-input-scanning/03-project-log-parser/log.txt similarity index 100% rename from 23-project-log-parser/02-project-log-parser/log.txt rename to 23-input-scanning/03-project-log-parser/log.txt diff --git a/23-project-log-parser/02-project-log-parser/log_err_missing.txt b/23-input-scanning/03-project-log-parser/log_err_missing.txt similarity index 100% rename from 23-project-log-parser/02-project-log-parser/log_err_missing.txt rename to 23-input-scanning/03-project-log-parser/log_err_missing.txt diff --git a/23-project-log-parser/02-project-log-parser/log_err_negative.txt b/23-input-scanning/03-project-log-parser/log_err_negative.txt similarity index 100% rename from 23-project-log-parser/02-project-log-parser/log_err_negative.txt rename to 23-input-scanning/03-project-log-parser/log_err_negative.txt diff --git a/23-project-log-parser/02-project-log-parser/log_err_str.txt b/23-input-scanning/03-project-log-parser/log_err_str.txt similarity index 100% rename from 23-project-log-parser/02-project-log-parser/log_err_str.txt rename to 23-input-scanning/03-project-log-parser/log_err_str.txt diff --git a/23-project-log-parser/02-project-log-parser/main.go b/23-input-scanning/03-project-log-parser/main.go similarity index 100% rename from 23-project-log-parser/02-project-log-parser/main.go rename to 23-input-scanning/03-project-log-parser/main.go diff --git a/23-project-log-parser/exercises/01-uppercaser/main.go b/23-input-scanning/exercises/01-uppercaser/main.go similarity index 100% rename from 23-project-log-parser/exercises/01-uppercaser/main.go rename to 23-input-scanning/exercises/01-uppercaser/main.go diff --git a/23-project-log-parser/exercises/01-uppercaser/solution/shakespeare.txt b/23-input-scanning/exercises/01-uppercaser/shakespeare.txt similarity index 100% rename from 23-project-log-parser/exercises/01-uppercaser/solution/shakespeare.txt rename to 23-input-scanning/exercises/01-uppercaser/shakespeare.txt diff --git a/23-project-log-parser/exercises/01-uppercaser/solution/main.go b/23-input-scanning/exercises/01-uppercaser/solution/main.go similarity index 100% rename from 23-project-log-parser/exercises/01-uppercaser/solution/main.go rename to 23-input-scanning/exercises/01-uppercaser/solution/main.go diff --git a/23-project-log-parser/exercises/02-unique-words/shakespeare.txt b/23-input-scanning/exercises/01-uppercaser/solution/shakespeare.txt similarity index 100% rename from 23-project-log-parser/exercises/02-unique-words/shakespeare.txt rename to 23-input-scanning/exercises/01-uppercaser/solution/shakespeare.txt diff --git a/23-project-log-parser/exercises/02-unique-words/main.go b/23-input-scanning/exercises/02-unique-words/main.go similarity index 65% rename from 23-project-log-parser/exercises/02-unique-words/main.go rename to 23-input-scanning/exercises/02-unique-words/main.go index 1a1e43c..4974290 100644 --- a/23-project-log-parser/exercises/02-unique-words/main.go +++ b/23-input-scanning/exercises/02-unique-words/main.go @@ -18,7 +18,6 @@ package main // 2. Scan the input using a new Scanner. // // 3. Configure the scanner to scan for the words. -// See the explanation inside the code below. // // 4. Count the unique words using a map. // @@ -27,13 +26,4 @@ package main // --------------------------------------------------------- func main() { - // I'll talk about this in the function values section later on. - // - // Simply put: - // Scanner can scan the lines, words, anything. - // Use the following code after creating the scanner - // to scan for the words instead. - // Below, I assumed that you put your scanner into the "in" variable. - - // in.Split(bufio.ScanWords) } diff --git a/23-project-log-parser/exercises/02-unique-words/solution/shakespeare.txt b/23-input-scanning/exercises/02-unique-words/shakespeare.txt similarity index 100% rename from 23-project-log-parser/exercises/02-unique-words/solution/shakespeare.txt rename to 23-input-scanning/exercises/02-unique-words/shakespeare.txt diff --git a/23-project-log-parser/exercises/02-unique-words/solution/main.go b/23-input-scanning/exercises/02-unique-words/solution/main.go similarity index 100% rename from 23-project-log-parser/exercises/02-unique-words/solution/main.go rename to 23-input-scanning/exercises/02-unique-words/solution/main.go diff --git a/23-project-log-parser/exercises/03-grep/shakespeare.txt b/23-input-scanning/exercises/02-unique-words/solution/shakespeare.txt similarity index 100% rename from 23-project-log-parser/exercises/03-grep/shakespeare.txt rename to 23-input-scanning/exercises/02-unique-words/solution/shakespeare.txt diff --git a/23-project-log-parser/exercises/03-grep/main.go b/23-input-scanning/exercises/03-grep/main.go similarity index 100% rename from 23-project-log-parser/exercises/03-grep/main.go rename to 23-input-scanning/exercises/03-grep/main.go diff --git a/23-project-log-parser/exercises/03-grep/solution/shakespeare.txt b/23-input-scanning/exercises/03-grep/shakespeare.txt similarity index 100% rename from 23-project-log-parser/exercises/03-grep/solution/shakespeare.txt rename to 23-input-scanning/exercises/03-grep/shakespeare.txt diff --git a/23-project-log-parser/exercises/03-grep/solution/main.go b/23-input-scanning/exercises/03-grep/solution/main.go similarity index 100% rename from 23-project-log-parser/exercises/03-grep/solution/main.go rename to 23-input-scanning/exercises/03-grep/solution/main.go diff --git a/23-input-scanning/exercises/03-grep/solution/shakespeare.txt b/23-input-scanning/exercises/03-grep/solution/shakespeare.txt new file mode 100644 index 0000000..cd46cce --- /dev/null +++ b/23-input-scanning/exercises/03-grep/solution/shakespeare.txt @@ -0,0 +1,12 @@ +come night come romeo come thou day in night +for thou wilt lie upon the wings of night +whiter than new snow on a raven's back +come gentle night come loving black-browed night +give me my romeo and when he shall die +take him and cut him out in little stars +and he will make the face of heaven so fine +that all the world will be in love with night +and pay no worship to the garish sun +oh i have bought the mansion of love +but not possessed it and though i am sold +not yet enjoyed \ No newline at end of file diff --git a/23-project-log-parser/exercises/README.md b/23-input-scanning/exercises/README.md similarity index 100% rename from 23-project-log-parser/exercises/README.md rename to 23-input-scanning/exercises/README.md