Git Product home page Git Product logo

inancgumus / learngo Goto Github PK

View Code? Open in Web Editor NEW
18.4K 315.0 2.5K 3.22 MB

โค๏ธ 1000+ Hand-Crafted Go Examples, Exercises, and Quizzes. ๐Ÿš€ Learn Go by fixing 1000+ tiny programs.

Home Page: http://twitter.com/inancgumus

License: Other

Go 99.93% HTML 0.01% Makefile 0.06%
golang go course exercise quizzes golang-examples learn-go learning-go learning-golang exercises

learngo's Introduction

Get my book!

Go by Example: Programmer's guide to idiomatic and testable code.

๐Ÿ‘‰ https://github.com/inancgumus/gobyexample

This book is what you need once you wrap up the exercises in this repository.

gobyexamplecover


A Huge Number of Go Examples, Exercises and Quizzes

Best way of learning is doing. Inside this repository, you will find thousands of Go examples, exercises and quizzes. I initially created this repository for my Go: Bootcamp Course. Later on, I added a lot of exercises, and I wanted every programmer who is not yet enrolled in the course to learn for free as well. So here it is. Enjoy.

Available in the following languages:

โค๏ธ Help other fellow developers

Sharing is free but caring is priceless. So, now please click here and share this repository on Twitter.

Stay in touch


License

Whole materials are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Creative Commons License

learngo's People

Contributors

akashkasurde avatar alecrajeev avatar alwaysshrek avatar aminbhr avatar anandprabhu avatar anhhh11 avatar db-s avatar dkaiser014 avatar fawni avatar firasuke avatar hakchealkim avatar inancgumus avatar jahway603 avatar jjatria avatar juanfmange avatar luisgsandoval avatar mikalstill avatar mohsin106 avatar nk412 avatar onurcangolge avatar parkma99 avatar paulwaldmann avatar rkhaled0 avatar sijoma avatar umm233 avatar xiyichan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learngo's Issues

Simplify primality test

Think this primality test should be simplified. You may use the following algorithm:

// 2 is a special case of prime, and if n < 2 then skip it. For others see bellow
if n > 2 {
  for i := 2; i <= i/2; i++ {
    if n % i == 0 {
       break
      //It's not a prime
    }
  }
  // It's a prime
}

I am referring to the simplification of the following part of the code:

invalid algorithm in CrunchThePrimes exercise

Part of the exercise (https://github.com/inancgumus/learngo/tree/master/13-loops/exercises/10-crunch-the-primes) asks the reader to re-implement this algorithm (https://stackoverflow.com/questions/1801391/how-to-create-the-most-compact-mapping-n-%e2%86%92-isprimen-up-to-a-limit-n/1801446#1801446) in order to build the logic to pass the challenge.

The expected output is:
// go run main.go 2 4 6 7 a 9 c 11 x 12 13
// 2 7 11 13
//
// go run main.go 1 2 3 5 7 A B C
// 2 3 5 7

Somehow, I kept getting 1 as part of the output of my implementation.

// go run main.go 2 4 6 7 a 9 c 11 x 12 13
// 2 7 11 13
//
// go run main.go 1 2 3 5 7 A B C
// 1 2 3 5 7

image

After further testing, it appears that the algorithm we are being asked to use is incorrect as it will return 1, even though 1 is not a prime number (https://www.wgtn.ac.nz/science/ask-a-researcher/is-1-a-prime-number)

learngo\03-packages-and-scopes\exercises\01-packages

// Copyright ยฉ 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package main

func main() {
greet()
bye()
}

I get this error when running the code!!

$ go run main.go

command-line-arguments

.\main.go:12:2: undefined: greet
.\main.go:13:2: undefined: bye

Please help!!

Invalid indirect issue in Pointers' exercise #3-fix-the crash

package main

import "fmt"

type computer struct {
	brand string
}

func main() {
	c := &computer{} 
	change(c, "apple")
	fmt.Printf("brand: %s\n", *c.brand) // need to remove *
}

func change(c *computer, brand string) {
	c.brand = brand
}

While printing pointed values, we get "invalid indirect of c.brand (type string)" issue.
The fix will be to call c.brand without *.

path searcher exercise solution always prints lower-cased paths (13-loops / exercise / 09 / 02)

This is a small issue, but one you may want to consider ๐Ÿ˜‰

With reference to learngo/13-loops/exercises/09-word-finder-exercises/02-path-searcher/solution/main.go

If a directory/folder legitimately contains a capital letter, converting w to lowercase results in the output displaying the path incorrectly lower-cased. One should only ToLower for the comparison, not the output to the user.

image

Sample correct vs incorrect output:
image

Translate to Vietnamese

Hello! I really love your project, can i fork the project, make a new branch, translate it, and then send a PR to you?

Incomplete choices on learngo-master\03-packages-and-scopes\questions\01-packages-A

Issue on line 46

Where to store the source code files that belong to a package?

  1. Each file should go into a different directory
  2. In a single directory CORRECT

Why a package clause is used in a Go source-code file?

  1. It's used for importing a package
  2. It's used for letting Go know that the file belongs to a package CORRECT
  3. It's used for declaring a new function

1: import statement does that.

3: func statement does that.

Where you should put the package clause in a Go source-code file?

  1. As the first code in a Go source code file CORRECT
  2. As the last code in a Go source code file
  3. You can put it anywhere

How many times you can use package clause for a single source code file?

  1. Once CORRECT
  2. None
  3. Multiple times

Which one is a correct usage of package clause?

  1. my package
  2. package main
  3. pkg main

Which one is correct?

  1. All files belong to the same package cannot call each others' functions
  2. All files belong to the same package can call each others' functions CORRECT

How to run multiple Go files?

  1. go run *.*go
  2. go build *go
  3. go run go
  4. go run *.go CORRECT

Issue: it can be go run .

4: You can also call it like (assuming there are file1.go file2.go and file3.go in the same directory): go run file1.go file2.go file3.go

Multiple Questions

Upon solving the exercises (in order) I compiled the following list of questions:

Ask about copyright

I wrote a small program named Golings,(inspired by Rustlings) lately . It almost has no exercises,and I need to add some exercises into it. can I use this source code as a part of my exercieses? I come here asking for copyright.

Happy New Year

[Good first issue]: Update README and include example links

The current README should include links (like Table of Contents) to the examples in the directories.

For example:

Get Started with Go

Let's install Go on your favorite operating system.

Write Your First Program

๐Ÿ™‡ Please contribute and add the other examples, exercises, and questions.

Lectures deleted on Udemy. Please restore.

I noticed that a couple dozen lectures have been deleted from the udemy page. The total duration of the course has come down from around 23 hours to 16 hours. That is 7 hours of content. I am guessing that this was just a lapse on your part accomodating the changes in udemy - requiring authors to reupload drm protected content or something. Please restore the deleted lectures asap. Also, you could consider uploading the course as a drm-free attachment in udemy as many other authors are doing right now.

Translate to spanish

How can i contribute to translate for spanish version? just making a pull request?

21-project-text-wrapper exceeds maxWidth line length

21-project-text-wrapper prints lines longer than 40 runes.

Since you're printing 40 runes, then continuing until a word break, the lines end up being longer than maxWidth by however much of a word is left.

example_output.txt

This doesn't seem to match the original request, nor what word processors do.

Richter Scale 2 typo

This is just my OCD. For the project learngo\12-switch\exercises\02-richter-scale-2\main.go in the comments for the expected output has the user expecting to put in plural and then return plural a different way.

//  go run main.go aliens
//   alien's richter scale is unknown

The expected input is "aliens" but then the s gets turned into 's which is getting added to all outputs. So, really it looks like the s vanishes.

Why use int64 instead of uint32?

Hey Inanc,

why do you use int64 for the speed of light variable? uint32 should be enough, right?.

https://github.com/inancgumus/learngo/blob/65e854c4ae4b56192054b7c93ed61295c79c01a6/09-go-type-system/exercises/01-optimal-types/solution/main.go#L32##

Is it also correct that the code from the non English letter prints this to the console:
"a non-english letter: 199"

Shouldn't 199 be the non-english letter instead of the number?
I used fmt.Printf("a non-english letter:%c", unicode) to correct this.

Thanks for your content btw!

Vulnerability of dependency "golang.org/x/crypto, golang.org/x/sys"

Hello, we are a team researching the dependency management mechanism of Golang. During our analysis, we came across your project and noticed that it contains a vulnerability (CVE-2022-27191, CVE-2022-29526).
In your project, the golang.org/x/crypto package is being used at version golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392, but the patched version is 0.0.0-20220314234659-1baeb1ce4c0b. To fix the vulnerability, we recommend modifying the go.mod file to update the version to 0.0.0-20220314234659-1baeb1ce4c0b or higher.

the golang.org/x/sys package is being used at version golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae, but the patched version is v0.1.0. To fix the vulnerability, we recommend modifying the go.mod file to update the version to v0.1.0 or higher.

Thank you for your attention to this matter.

Should it be a max and not min?

In this part of the code, you refer to the boundary for rand.Intn should be min. If it is min then the max generated number will be from [0, min) + 1, meaning that the guess which is > min will not be taken into count.
My understanding is it should be:

max := guess
if guess1 > max {
  max = guess1
}

This way we will evaluate against both guess and guess1.

switch - exercise 02 richter scale - solution wrong

running main.go with a string of 2 words produces wrong output. For example one of the test cases in the exercise is go run main.go "very minor" . This test produces wrong output as the program is looking for os.Args[1]

French language translation

Hello, I was wondering if you plan to add a french language translation ?
I can read english that's not a problem but if a french translation is planned I'm offering my help, as a French developper I can do it ! :)

invalid expression in questions.md

In 08-numbers-and-strings/02-strings/questions/questions.md, the first question is an invalid expression. Trying to build

package main

import (
	"fmt"
)

func main() {
	s := "\"Hello\\"" + ` \"World\"`
	fmt.Println(s)
}

results in

./prog.go:8:18: syntax error: unexpected literal " + ` \"World\"` at end of statement
./prog.go:8:34: newline in string

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.