Category Archives: Go (en)

Golang. Sum of consecutive numbers

The problem is to find in an array of integers a sequence of consecutive numbers whose sum is equal to n. Our program will read a list of integers (e.g., 5 2 3 4 6 1 4 10 1), followed … Continue reading

Posted in Go (en) | Leave a comment

Go Language. Map Exercise

Based on the list of dungeon raids, find the top player in the guild 🙂  Example of input:

Posted in Go (en) | Leave a comment

Golang. Exercises for slices

Let’s look at some examples of slice programs in Go. First one… The user enters two rows of numbers. Our task is to collect them in one slice, removing duplicates. As an exercise, we will not use cards, but ordinary … Continue reading

Posted in Go (en) | Leave a comment

Golang. Selection Sort

Selection sort is a simple sorting algorithm that repeatedly selects the minimum item from the unsorted part of the list and swaps it with the first unsorted item. Example code in Go:

Posted in Go (en) | Leave a comment

Golang. Bubble sorting

О… how much is in this “Chink”-sound!.. We learned to sort by “bubble” back in school (hello, Mr.Obama!). Why not make a code for this sorting in Go? 😀 Even if it is seldom useful, it’s a good exercise for … Continue reading

Posted in Go (en) | Leave a comment

Golang. Fisher-Yates algorithm

The user enters any number, letter, word, or whatever he wants, separated by a space. Let’s say he even enters card values (poker hand), such as A 3 J Q 10. Our job is to shuffle these cards. To do … Continue reading

Posted in Go (en) | Leave a comment

Golang. Console calculator

Let’s write a simple console calculator that performs basic arithmetic operations. First, we give it the numbers with which we want to perform operations using the add <number> command (we can give several numbers). Then we can use the commands … Continue reading

Posted in Go (en) | Leave a comment

Golang. Interfaces

The most cumbersome for newcomers to golang are the interfaces. Here are some examples of code I took apart to “smoke” them, I hope they will help you too. The idea is to look at the code, then close it … Continue reading

Posted in Go (en) | Leave a comment

Golang. Closures and Fibonacci Numbers

Assignment number 26 in the Go Tour. Implement a Fibonacci function that returns a function (closure) that returns consecutive Fibonacci numbers (0, 1, 1, 1, 2, 3, 5, …). Solution:

Posted in Go (en) | Leave a comment

Golang. Exercise: Maps

So, there we have exercise 23 from Go Tour. Implement the WordCount function. It should return a map (data type map) of the counts of each “word” in the string s. The function wc.Test runs a set of tests against … Continue reading

Posted in Go (en) | Leave a comment

Golang. Two-dimensional slices (2D)

From chapter 18 of Go tour.. In general, the tasks in this ‘tour’ are quite itchy B) So… Implement the Pic function. It should return a fragment of length dy, each element of which is a fragment of dx 8-bit … Continue reading

Posted in Go (en) | Leave a comment

Golang. Point belong to the circle?

The last example on Pythagoras’ theorem is quite simple. Let’s take a problem from the same topic, but more complicated. Suppose we have a circle in the center of x-axis and y-axis (i.e. center at coordinates 0,0). Let’s write a … Continue reading

Posted in Go (en) | Leave a comment

Golang. Pythagoras Theorem

Continue practicing Go and remembering the school curriculum “Pythagoras pants are equal on all sides!” Or to paraphrase in a more boring version: the square of the length of the hypotenuse of a right triangle is equal to the sum … Continue reading

Posted in Go (en) | Leave a comment

Golang. Character string into a numeric slice

Let’s write a simple program in Go that will take a string, break it down into slice elements, and convert each element into a number. First, all the code, and I will break it down in detail below:

Posted in Go (en) | Leave a comment

Golang. Number into words

Let’s write a program that prints numbers as text. Let’s limit it to a range of 1 to 1000. Here is the first example of code, a fuzzy one:

Posted in Go (en) | Leave a comment

Golang: Newton’s algorithm

Task number 8 in golang tour… Cycles and functions To play with functions and loops, let’s implement the square root function: Given a number x, we want to find the number z for which z² is closest to x. Computers … Continue reading

Posted in Go (en) | Leave a comment

Golang. The average of the numbers entered in the string

Let’s write a program that reads N numbers separated by a space (in one line) and calculates their average value. The task seems to be simple, but it can be solved in different ways. Here is my version:

Posted in Go (en) | Leave a comment