Welcome to Day 22 of the Perl 6 One-Liner Advent Calendar! Today, we will continue working with files, and the goal for today is to create a one-liner to print the lines of a text file in reversed order (as tail -r does it). The first one-liner does the job with the STDIN stream: .say … Continue reading “๐ 22/25. Reversing a file with Perl 6”
๐ 21/25. Merging files horizontally in Perl 6
Welcome to Day 21 of the Perl 6 One-Liner Advent Calendar! Only a few days left until the end of this season of advent calendars, so letโs pack as many things as possible in the remaining days, and today we’ll merge a few files into a single file ๐ Our todayโs goal is to take … Continue reading “๐ 21/25. Merging files horizontally in Perl 6”
๐ 20/25. Using command-line options in Perl 6 one-liners
Welcome to Day 20 of the Perl 6 One-Liner Advent Calendar! So far, we created about 25 different one-liners, but never talked about the command-line options that the Rakudo Perl 6 compiler offers to us. -e The first option to know when working with (Rakudo) Perl 6 is -e. It takes a string with your Perl 6 one-liner … Continue reading “๐ 20/25. Using command-line options in Perl 6 one-liners”
๐ 19/25. Using map and Seq to compute the value of ฯ in Perl 6
Welcome to Day 19 of the Perl 6 One-Liner Advent Calendar! Today, we will be computing the value of ฯ using two different methods. The goal of this blog post is to play with different approaches to generate numeric sequences. Pre-party Of course, in Perl 6 you donโt need to calculate the value of ฯ … Continue reading “๐ 19/25. Using map and Seq to compute the value of ฯ in Perl 6”
๐ 18/25. Renaming files with Perl 6
Welcome to Day 18 of the Perl 6 One-Liner Advent Calendar! Today, there will be a true one-liner, in the sense that you run it from the terminal as a devops. Our task is to rename all the files passed in the command-line arguments and give the files sequential numbers in the preferred format. Here … Continue reading “๐ 18/25. Renaming files with Perl 6”
๐ 17/25. Playing with prime numbers in Perl 6
Welcome to Day 17 of the Perl 6 One-Liner Advent Calendar! Today, weโll have two one-liners, both generating some prime numbers. Part 1 First, let us solve Problem 7 of Project Euler, where you need to print the 10001st number (having the first being 2). Perl 6 is good at prime numbers, as it has … Continue reading “๐ 17/25. Playing with prime numbers in Perl 6”
๐ 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”