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 unsigned integers. When you run the program, it will display your picture by interpreting the integers as grayscale (or blue) values. It will draw something like the picture on the left..
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 test for finding an arbitrary point inside the circle.

Here again Pythagoras will help us. In the general case, the formula is as follows:

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 of the squares of the cathetuses: c^2 = a^2 + b^2

Our titanic task is this: find the third side of a right triangle. Here’s the code:

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:

Continue reading

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:

Continue reading

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 usually calculate the square root of x using a loop. Starting with some assumed z, we can adjust z based on how close z² is to x, getting a better guess:

z -= (z * z - x) / (2 * z)

igroglaz’ note: 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:

Continue reading

Posted in Go (en) | Leave a comment

Golang. Median

Today let’s remember what the median is and how to find it. The median is a number exactly in the middle of an ordered list. It is a very useful thing in statistics and it helps to see the real picture, not the average temperature in the hospital 🙂 For example, we have a list of 55, 1, 22, 7, 92… to find the median:

  1. we order it. We get: 1, 7, 22, 55, 92
  2. look for the one in the middle… that’s 22

If we have an even number of elements in the list, then the median is the average of the sum of two neighboring values. Anyway, here is the code of the simplest variant:

Continue reading

Posted in Go (en) | Leave a comment

Golang. Number of letters in a sentence

Calculate the number of characters in the text – how many which letter occurs how many times. You can do this with maps, but there is another, C-style way: character arithmetic:

Continue reading

Posted in Go (en) | Leave a comment

Golang. Funny basic example of `if/else`

There is a resource for newcomers to the Go language – “A Tour of Go“. There’s a funny example in the beginning by number 7.. Continue reading

Posted in Go (en) | Leave a comment

Golang. Simple programs for beginners

The Go language is very similar to C. Here are some simple programs.

Let’s begin… Calculate 2 to the 12th power.

Continue reading

Posted in Go (en) | Leave a comment

Run notepad++ from the Windows console

Sometimes in Windows, you have to use cmd console, create files in it, etc. So it is convenient to bind file opening in npp (notepad++) to alias npp <file name>. There are different ways to do it, but the easiest is this:

1. create a .bat file named npp.bat and write there

@echo off start "" "C:\Program Files\Notepad++\notepad++.exe" %*

2. we just put it into the folder C:\Windows

Hallelujah! Now you can open files in your favorite npp from the console 🙂

Posted in Notepad++ (en) | Leave a comment

CodeBlocks debugging global variables

I love CodeBlocks IDE for my C language projects… But biggest blunder of CodeBlocks IDE is that you must manually add to ‘Watch’ global variables every @#$% time when debugging. Eg in C++ Builder and other IDEs there is no such problem… Why, why they did it?..

Ok, ok.. “One should avoid to use global variables”, – many will say. But using globals for tiny programs it’s actually the most convenient way to do fast tasks. And AFAIK most of the projects which use CodeBlocks is actually enthusiasts projects.. So it’s really out of scope feature there.

Posted in IDE (en) | Leave a comment

Returning the old terminal after Windows 11 update KB5019509

Got the update for Windows today – KB5019509 and the terminal’s arm was torn off. That is, it stopped displaying console programs like my Roguelike game. The update that broke it, adds tabs to the console, while breaking everything else… well, not the point (by the way, to see the latest Windows updates, type wmic qfe list into cmd).

To fix it:

Click on the header of the terminal window -> Properties

In Default Terminal Application put Windows Console Host

Restart the console and hallelujah! We got our oldschool console back. Old Billy’s nose lost the game again ;P

Posted in Windows 11 (en) | Leave a comment

Add “New” .txt in Windows 11 to the context menu

Add “New” .txt in Windows 11 to the context menu

Windows Registry Editor Version 5.00
@="Text File"

Run it, kill the explorer and enjoy the ability to create .txt files 😉

Continue reading

Posted in Windows 11 (en) | Leave a comment

Remove “New” file types from the context menu in Windows 11

I switched to Windows 11 with a crunch. Terrible interface. Billy, why?!

In general, one of the crutches that you have to substitute in order not to go crazy – removing @#$% file types from the context menu “New”. It’s done like this (works on Win 10 as well):

  • regedit
  • look for the right extension, e.g. .odg (OMG, why does LibreOffice add his holey hats there).
  • There, look for the ShellNew section and delete the hell out of it (Billy, they’re waiting for you there with a really hot pan).
Posted in Windows 11 (en) | Leave a comment

What do you program in Python? Real-world applications with library examples

When I started learning Python, I got curious about what people write in this language. If you look at it from a general perspective, it seems like Python is used everywhere – it’s such a super universal language that you can write computer games, create a social network with pictures, make a website, and whatever else you want. Just learn Python and you can program whatever you want,
anything you want. It’s like saying that it’s like an entire house is built out of plaster… it’s only covered in plaster, but it’s built with concrete, for example. Python is plaster in that sense.
Continue reading

Posted in Python (en) | Leave a comment