🎄 16/25. Distance between two points in Perl 6

Welcome to Day 16 of the Perl 6 One-Liner Advent Calendar! Today, we’ll solve a simple problem and will find the distance between two points on a surface. Here’s an illustration to help to formulate the task. Our goal is to find the distance between the points A and B. To make the answer more … Continue reading “🎄 16/25. Distance between two points in Perl 6”

🎄 15/25. Playing with Fibonacci numbers in Perl 6

Welcome to Day 15 of the Perl 6 One-Liner Advent Calendar! Today, there will be two one-liners, and they both generate Fibonacci numbers. Yes, most likely, you never used such numbers in real code, and, again, most likely, you solved many educating problems with them. Nevertheless, today, let’s solve the Problem 25 of the Project … Continue reading “🎄 15/25. Playing with Fibonacci numbers in Perl 6”

🎄 14/25. Another solution of yesterday’s problem

Welcome to Day 14 of the Perl 6 One-Liner Advent Calendar! Today, we are presenting another solution of the problem we were solving yesterday. The task was to count all Sundays that fall on the first of the month in the XX century. Yesterday, we just scanned through all the days in the whole century, … Continue reading “🎄 14/25. Another solution of yesterday’s problem”

🎄 13/25. How many days in the century match the condition?

Welcome to Day 13 of the Perl 6 One-Liner Advent Calendar! Today’s one-liner will be quite long, and it would be better to write it in two lines, but it will show a very nice feature of Perl 6’s Date objects: it can be easily used in a range. Today, we are solving Problem 19 … Continue reading “🎄 13/25. How many days in the century match the condition?”

🎄 12/25. What’s behind 0.1+0.2 in Perl 6

Welcome to Day 12/25 of this year’s Perl 6 One-Liner Advent Calendar! Today, we will examine a one-liner that computes a zero. say 0.1 + 0.2 – 0.3 If you are familiar with programming, you know well that as soon as you start using floating-point arithmetic, you loose precision, and you can face the small … Continue reading “🎄 12/25. What’s behind 0.1+0.2 in Perl 6”

🎄 11/25. Solving the Problem 34 in Perl 6

Welcome to Day 11 of the Perl 6 One-Liner Advent Calendar! Today, the calendar post is totally devoted to the solution of problem 34 of Project Euler. Once again, let me warn you to pause reading if you want to find your own solution prior to seeing mine. So, the task is to find the … Continue reading “🎄 11/25. Solving the Problem 34 in Perl 6”

🎄 10/25. Reduction operator in Perl 6

Welcome to Day 10 of the Perl 6 One-Liner Advent Calendar! Today, there will be three one-liners instead of a regular one. Our today’s guest is a reduction construction with a pair of square brackets. When they do not surround an array index, they work in a completely different field. Example 1 The most classical … Continue reading “🎄 10/25. Reduction operator in Perl 6”

🎄 9/25. More on X, .., and … in Perl 6

Welcome to Day 9 of the Perl 6 One-Liner Advent Calendar! On Day 6, we had a construct with a cross-operator, (999…100) X* (999…100). Today, we’ll dive into a similar construction from November: 1..10 X* 1..10 It prints the items of the product table for the numbers from 1 to 10: (1 2 3 4 … Continue reading “🎄 9/25. More on X, .., and … in Perl 6”

🎄 8/25. Adding up even Fibonacci numbers in Perl 6

Welcome to Day 8 of this year’s Perl 6 One-Liner Advent Calendar. It is about ¼ of the whole series, and don’t forget that you can type ¼ instead of 0.25 in Perl 6! Today, we are solving problem 2 from Project Euler. The task is to find the sum of all even Fibonacci numbers below four … Continue reading “🎄 8/25. Adding up even Fibonacci numbers in Perl 6”

🎄 7/25. The joy of Unicode in Perl 6

Welcome to Day 7 of the Perl 6 One-Liner Advent Calendar! Today, we’ll look at the month of March in the Perl 6 Calendar 2019: The code here is using three characters outside of the ASCII land. We can even add one more: say π × $𝜌² In Perl 6, you can freely use Unicode … Continue reading “🎄 7/25. The joy of Unicode in Perl 6”

🎄 6/25. Testing palindromic numbers in Perl 6

Welcome to Day 6 of the Perl 6 One-Liner Advent Calendar! As promised yesterday, today we’ll be solving problem 4 of Project Euler. Let me once again remind you that you can pause reading and solve the problem yourself first. My intention is to demonstrate the beauty of Perl 6 and Perl in general. So, … Continue reading “🎄 6/25. Testing palindromic numbers in Perl 6”

🎄 5/25. What’s the date today in Perl 6?

Welcome to Day 5 of this lovely Perl 6 One-Liner Advent Calendar! Today, we’ll answer the question of what’s the date today (and tomorrow we can talk about palindromes if you want). So, to print the answer, you can use the following line of Perl 6 code: DateTime.now.yyyy-mm-dd.say It looks transparent and prints the date … Continue reading “🎄 5/25. What’s the date today in Perl 6?”

🎄 4/25. Working with big numbers in Perl 6

Welcome to Day 4 of the Perl 6 One-Liner Advent Calendar! Today, we’ll look at the Problem 13 of Project Euler. Let me show a screenshot of it: Indeed, it looks huge, and the task is to find the first ten digits of the sum of a hundred integers, each consisting of 50 digits. Sounds … Continue reading “🎄 4/25. Working with big numbers in Perl 6”

🎄 3/25. Generating random integers in Perl 6

Welcome to Day 3 of the Perl 6 One-Liner Advent Calendar! Today, we will generate random numbers. You may ask, what’s the deal with it, isn’t it a routine task to call a kind of a rand function? Well, in some sense, yes, but in Perl 6, you might prefer calling a method.  Let’s look at the … Continue reading “🎄 3/25. Generating random integers in Perl 6”

🎄 2/25. Grepping dividable numbers in Perl 6

Welcome to Day 2 of the Perl 6 One-Liner Advent Calendar! Today, we’ll solve a nice task from Project Euler with number 1. Once again, let me warn you that the rest of the text contains a solution, so you are welcome to make a pause to think of your own solution first. But I am … Continue reading “🎄 2/25. Grepping dividable numbers in Perl 6”

🎄 1/25. Generating random passwords in Perl 6

Welcome to the first day of the brand new Perl6.Online Advent Calendar! This year, its theme is Perl 6 One-Liners (a pun from perl6.onliners). Thus, welcome to this year’s Perl 6 One-Liner Advent Calendar. The whole perl6.online blog was initially planned to be daily, so it’s a great opportunity to keep the pace for at least another … Continue reading “🎄 1/25. Generating random passwords in Perl 6”

📘 Variables in Perl 6: Introspection

Due to the mechanism of introspection, it is easily possible to tell the type of the data living in a variable (a variable in Perl 6 is often referred as a container). To do that, call the predefined WHAT method on a variable. Even if it is a bare scalar, Perl 6 treats it internally … Continue reading “📘 Variables in Perl 6: Introspection”