I published my new book: A Language a Day, which is a collection of brief overviews to 21 programming languages.
A Language a Day
I published my new book: A Language a Day, which is a collection of brief overviews to 21 programming languages.
Science, Programming, Electronics, Languages
I published my new book: A Language a Day, which is a collection of brief overviews to 21 programming languages.
I published my new book: A Language a Day, which is a collection of brief overviews to 21 programming languages.
In this post I am demonstrating the solutions of a programming problem in 22 different languages: Raku, Python, C++, Perl, Ruby, Scala, C#, Dart, Julia, D, Lisp, C, JavaScript (Node.js), Java, Rust, Pascal, Go, Lua, Fortran, PHP, Kotlin, and Bash.
In this post I am demonstrating the solutions of a programming problem in 22 different languages: Raku, Python, C++, Perl, Ruby, Scala, C#, Dart, Julia, D, Lisp, C, JavaScript (Node.js), Java, Rust, Pascal, Go, Lua, Fortran, PHP, Kotlin, and Bash.
This week, I wrote a few programs solving the task of this week’s Weekly Challenge. I already explained the solution in the Raku programming language. In this post, I’d like to demonstrate other solutions. The key point is that they not only use different programming language but also approach the problem differently and implement different algorithms.
This week, I wrote a few programs solving the task of this week’s Weekly Challenge. I already explained the solution in the Raku programming language. In this post, I’d like to demonstrate other solutions. The key point is that they not only use different programming language but also approach the problem differently and implement different algorithms.
Hello, here is my solution to the Task 2 of Week 75 of the Weekly Challenge solved in the Raku programming language.
You are given an array of positive numbers @A. Write a script to find the largest rectangle histogram created by the given array.
Hello, here is my solution to the Task 2 of Week 75 of the Weekly Challenge solved in the Raku programming language.
You are given an array of positive numbers @A. Write a script to find the largest rectangle histogram created by the given array.
The Perl Weekly Challenge was renamed to The Weekly Challenge recently, so there’s a bigger chance that more solutions in other programming languages appear there.
In the two Raku solutions in this post, you can see how you can use the built-in Bag data type.
Task 1. Majority Element (Raku and C++ solutions). Task 2. First Non-Repeating Character (Raku solution).
The Perl Weekly Challenge was renamed to The Weekly Challenge recently, so there’s a bigger chance that more solutions in other programming languages appear there.
In the two Raku solutions in this post, you can see how you can use the built-in Bag data type.
Task 1. Majority Element (Raku and C++ solutions). Task 2. First Non-Repeating Character (Raku solution).
In this post, I am writing the solution for the second task in this week’s challenge in both Raku and C++.
In this post, I am writing the solution for the second task in this week’s challenge in both Raku and C++.
Some time ago, I published an article about using NativeCall in Raku to call functions written in C. Today, let’s see how you can call simple functions written in C++ or in Fortran.
Some time ago, I published an article about using NativeCall in Raku to call functions written in C. Today, let’s see how you can call simple functions written in C++ or in Fortran.
About this ‘A Language a Day’ Advent Calendar This article became a part of my book ‘A Language a Day’, which you can get in both electronic and paper format. Languages covered in the book: C++, Clojure, Crystal, D, Dart, Elixir, Factor, Go, Hack, Hy, Io, Julia, Kotlin, Lua, Mercury, Nim, OCaml, Raku, Rust, Scala, and … Continue reading “Modern C++ at a Glance — A Language a Day, Advent Calendar Day 5/24”
Initializer lists, or if you prefer, initialiser lists, are a great addition of C++ 11, which allows you to 1) initialize your list-like classes and 2) uniform the initialisation of such objects comparing to what you can do with the built-in types. Let us demonstrate it on the following example, which uses a simple array … Continue reading “Initializer lists in C++”
The old-days way of acquiring memory resources is to have a pair of malloc and free calls. The C++’s addition, the new and delete keywords simplified the syntax, but did not eliminate the problem of proper memory management. The Problem Here is a typical approach: you create some place for your data, get a pointer, … Continue reading “Avoiding naked new in modern C++”
Here’s a problem to solve: you have two threads, each incrementing the same single counter N times. What is the state of the counter at the end of the program? A straightforward solution A naïve C++ program can be written using the standard library threads like this: #include <iostream> #include <thread> int counter; void f() { for (int c = 0; c != 100000; c++) counter++; } int main() { std::thread thread_a {f}; … Continue reading “Concurrent atomic operations in C++ and Raku”
The range-based for loop that is available since the C++ 11 standard, is a wonderful mean of making the code compact and clean. This post is totally dedicated to a single go: to show the difference between iterating using STL iterators and using for ranges. Here’s a simple code that creates a vector of integers … Continue reading “Iterators vs. auto in C++”
The so-called range-based for loop appeared in the C++ 11 standard, together with the auto keyword gives us a very powerful and idiomatic way of looping over things. Let’s start with a simple array. #include <iostream> int main() { int odd_data[] = {1, 3, 5, 7, 9}; for (auto x : odd_data) std::cout << x << “\n”; } Here, the for loop goes over all the elements of the odd_data array, and you … Continue reading “A range-for loop in C++”
In the previous post, we were talking about the constexpr keyword in modern C++. It was added to the C++ 11 standard, but in C++ 14, it got a very nice addition. In particular, you can do more in constexpr functions now. Consider the following program that wants to pre-compute a factorial of 5. #include <iostream> … Continue reading “constexpr in C++ 11 and C++ 14”
The constexpr keyword is a relatively new addition to C++. You need to use the C++11 standard in order to compile the following programs: g++ -std=c++11 test.cpp Let’s examine what the keyword is about. There’s no difficulty to split it into words to get the meaning: constant expression. In practice, constant expression means that the … Continue reading “constexpr in C++”