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:
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:
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
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:
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:
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:
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:
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
The Go language is very similar to C. Here are some simple programs.
Let’s begin… Calculate 2 to the 12th power.
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 🙂
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.
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
Add “New” .txt in Windows 11 to the context menu
Windows Registry Editor Version 5.00 [-HKEY_CLASSES_ROOT\.txt\ShellNew] [HKEY_CLASSES_ROOT\.txt\ShellNew] "NullFile"="" [-HKEY_CLASSES_ROOT\txtfilelegacy] [HKEY_CLASSES_ROOT\txtfilelegacy] @="Text File" [HKEY_CLASSES_ROOT\txtfilelegacy\shell] [HKEY_CLASSES_ROOT\txtfilelegacy\shell\printto] "NeverDefault"="" [HKEY_CLASSES_ROOT\txtfilelegacy\shell\printto\command] @=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\ 00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,6e,00,6f,00,\ 74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,20,00,2f,00,70,00,74,\ 00,20,00,22,00,25,00,31,00,22,00,20,00,22,00,25,00,32,00,22,00,20,00,22,00,\ 25,00,33,00,22,00,20,00,22,00,25,00,34,00,22,00,00,00
Run it, kill the explorer and enjoy the ability to create .txt files 😉
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):
.odg
(OMG, why does LibreOffice add his holey hats there).ShellNew
section and delete the hell out of it (Billy, they’re waiting for you there with a really hot pan).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
Assembler is a low-level programming language. Below it there is only machine code (zeros and ones).
Why learn assembler?
Hello World in assembly language. How much fun is in that! For starters, here’s what we’re going to dig into in asm, the classics:
#include <stdio.h> int main(void) { printf("Hello, world\n"); return 0; }
On GNU assembly it would be something like this:
Continue reading
Sometimes your program process can stuck and trigger error like this:
Couldn’t bind to the port
Ok, we have such check in out sockets C code:
if (bind (socket_desc, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0) printf("Couldn't bind to the port\n");
And it return negative value.. How to fix it?
netstat -ano | findstr :<port number>
netstat -ano | findstr :2000
TCP 127.0.0.1:2000 0.0.0.0:0 LISTENING 3560
taskkill /pid <process ID> /F
taskkill /pid 3560 /F
SUCCESS: The process with PID 3560 has been terminated.
Enjoy!