inancgumus / learngo Goto Github PK
View Code? Open in Web Editor NEWโค๏ธ 1000+ Hand-Crafted Go Examples, Exercises, and Quizzes. ๐ Learn Go by fixing 1000+ tiny programs.
Home Page: http://twitter.com/inancgumus
License: Other
โค๏ธ 1000+ Hand-Crafted Go Examples, Exercises, and Quizzes. ๐ Learn Go by fixing 1000+ tiny programs.
Home Page: http://twitter.com/inancgumus
License: Other
Hi, The slack invite has expired.
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:
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
// 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
.\main.go:12:2: undefined: greet
.\main.go:13:2: undefined: bye
Please help!!
Are there some examples covering concurrency w/ Goroutines & Channels here or in the udemy course?
Hey Inanc,
why do you use int64 for the speed of light variable? uint32 should be enough, right?.
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!
Hello! I really love your project, can i fork the project, make a new branch, translate it, and then send a PR to you?
Can you please further elaborate on what the exercise/question is/was for this solution?
Thanks for your time and effort.
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.
What's wrong with the numbering of the subdirectories inside 06-variables/04-assignments?
The current README should include links (like Table of Contents) to the examples in the directories.
For example:
Let's install Go on your favorite operating system.
๐ Please contribute and add the other examples, exercises, and questions.
Text Wrapper Challenge Guideline says, "The program should not cut the words before they finish. Instead, it should put the whole word on the next line." That means each line must contain 40 characters at most. But the solution doesn't follow this rule; it prints the whole word even if it makes the current line width more than 40 characters.
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.
This doesn't seem to match the original request, nor what word processors do.
Suggested fix
for in.Scan() {
w := strings.ToLower(in.Text())
if words[w] {
fmt.Println("TWICE!")
return
}
words[w] = true
}
How can i contribute to translate for spanish version? just making a pull request?
Now it is stable to use Go-lang anywhere in the computer no need to be limited to one folder.
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 *.
Upon solving the exercises (in order) I compiled the following list of questions:
What's wrong with the numbering of the subdirectories inside 06-variables/04-assignments?
Can you please further elaborate on what the exercise/question is/was for this solution?
Why is 03-refactor-feet-to-meters not in the exercises section of 10-constants
?
Why isn't 11-if/02-if-statement/05-challenge-userpass in the exercises section?
Why isn't 14-arrays/06-challenge-moodly and 14-arrays/10-challenge-moodly-2 not in the exercises ection of 14-arrays
?
What's wrong with the commented numbers in 16-slices/12-full-slice-expressions/2-example (#4
is before #3
and so on) and in 16-slices/13-make/2-example/ (#6
repeated twice and #7
is before the second #6
) and in 16-slices/14-copy/02-hacker-incident/ (No #8
and #1
after #9
)?
Why aren't the solutions for chapters 20 and 21 in their own respective solution
directory?
The website link located here, https://github.com/inancgumus/learngo/blob/master/11-if/exercises/04-vowel-or-cons/main.go#L18, does not work. Not sure of a better link, or I would have changed and submitted a PR for the change.
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]
Issue on line 46
1:
import
statement does that.3:
func
statement does that.
package clause
in a Go source-code file?package clause
for a single source code file?package clause
?my package
package main
pkg main
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
Hi @inancgumus ,
Firstly, thank you for your very instructive share.
I propose you to use string.ContainsAny instead of strings.IndexAny as a new solution for the exercice 04-vowel-or-cons of the chapter 11-if.
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.
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 ! :)
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.
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
The operator is passed to main.go with doublequotes which are not escaped while checking in the solution. I resolved by adding backslashes but just want to get a comment as i am learning.
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.
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
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)
Why is 03-refactor-feet-to-meters not in the exercises section of 10-constants
?
the random number should not be effected by the users entry. In the example passing in one will always result in you winning since Intn is limited to the guess.
The range for the random number should be a constant
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.