πŸ’‘ 106. Gnome sort in Perl 6

Our today’s topic is the Gnome sort, which is also referred to as Stupid sort. To sort an array using this method, you scan the data from left to right and check the two adjacent items to see if they are ordered properly. If they are, you go forward. If not, you swap the elements … Continue reading “πŸ’‘ 106. Gnome sort in Perl 6”

πŸ’‘ 105. Pancake sort in Perl 6

The Pancake sort is an interesting method of sorting data, as unlike more traditional sorting algorithms, it operates with piles of data on each step. You have to imagine data as a pile of pancakes, the values corresponding to the size of pancakes. The only allowed operation is flipping a pile of β€˜pancakes.’ It can … Continue reading “πŸ’‘ 105. Pancake sort in Perl 6”

πŸ’‘ 104. Stooge sort in Perl 6

Have you ever heard of the Stooge sort algorithm? If not, it is quite interesting to learn it. The idea is clear, while you maybe need some time to see if it really works. So, take a list of numbers and swap the first and the last elements if they are not sorted properly (that … Continue reading “πŸ’‘ 104. Stooge sort in Perl 6”

πŸ’‘ 103. Merge sort in Perl 6

Welcome to another sorting episode, this time we’ll talk about Merge sort in Perl 6. In Merge sort, you first split the data into halves until the pieces become atomic (in the original meaning of the word), that is either each piece contains a single element, or, after the current split, the second part contains … Continue reading “πŸ’‘ 103. Merge sort in Perl 6”

πŸ’‘ 102. Insertion sort in Perl 6

Today, we are investigating the Insertion sort algorithm and its possible implementation in Perl 6. The algorithm’s complexity is O(n2), but it is a good candidate to practice some Perl 6. The idea is simple. You find the minimum value in the array and put it to the first position. Then you scan the data … Continue reading “πŸ’‘ 102. Insertion sort in Perl 6”

πŸ’‘ 101. Quick sort in Perl 6

Today, let’s look at another, and presumably the most well known method of sorting data, Quick sort. The algorithm requires you to select the so-called pivot, one of the element from the data, and split the rest in two parts: the elements less than the pivot, and the elements more or equals to the pivot. … Continue reading “πŸ’‘ 101. Quick sort in Perl 6”

πŸ’‘ 100. Bubble sort in Perl 6

Hey everyone, let’s implement some algorithms in Perl 6. The first one will be the classical Bubble sort. In essence, you scan the data from left to right and swap the two adjacent items if they are not ordered properly yet. Repeat until the whole data list is ordered. Here’s the initial straightforward implementation: sub … Continue reading “πŸ’‘ 100. Bubble sort in Perl 6”

πŸ“Ί Creating a compiler in Perl 6

At the German Perl Workshop 2019 in Munich, I gave a presentation about how to create compilers and interpreters using Perl 6 grammars. This talk differs from my previous talks on this subject, so if you’ve seen them, I hope you will also enjoy this one. There was a video recording during the talk, I … Continue reading “πŸ“Ί Creating a compiler in Perl 6”

πŸ“Ί Perl 6 as a new tool for language compilers

Here’s my recent talk from FOSDEM in Brussels, given on 3 February 2019. Perl 6 grammars are a great way to describe the grammar and implement an interpreter or a compiler of DSL or a programming language. In this talk, I will demonstrate how you can do it. During the talk, we will create an … Continue reading “πŸ“Ί Perl 6 as a new tool for language compilers”

πŸŽ„ 26/25. Overview of the Perl 6 One-Liner Advent Calendar 2018

The Perl 6 One-Liner Advent Calendar 2018 is over! Let’s make a quick overview of what we have covered so far. There were a few themes covered. First, some one-liners from the Perl 6 Calendar 2019 were explained in more detail. We looked at how to generate random passwords and random integers, how to print … Continue reading “πŸŽ„ 26/25. Overview of the Perl 6 One-Liner Advent Calendar 2018”

πŸŽ„ 25/25. Tips and ideas for the Perl 6 Golf code

Welcome to Day 25, the last day of the Perl 6 One-Liner Advent Calendar! Traditional advent calendars have only 24 entries, and our bonus post today will be dedicated to some tips and tricks that you can use in Perl 6 golf contest. There is a great site, code-golf.io, where you can try solving a … Continue reading “πŸŽ„ 25/25. Tips and ideas for the Perl 6 Golf code”

πŸŽ„ 24/25. Reading files with $*ARGFILES in Perl 6

Welcome to Day 24 of the Perl 6 One-Liner Advent Calendar! In the previous days, we were reading text files, so it would be logical to talk about $*ARGFILES, a built-in dynamic variable that may be handy when working with multiple input files. How do you read two or more files passed in the command-line? … Continue reading “πŸŽ„ 24/25. Reading files with $*ARGFILES in Perl 6”

πŸŽ„ 23/25. Calculating totals with Perl 6

Welcome to Day 23 of the Perl 6 One-Liner Advent Calendar! End of the year is the time when people evaluate there year results, and Perl 6 can help with that, too. Today, we’ll see a one-liner that calculates totals for the columns of a table. Here’s some sample data in a file: 100.20 303.50 … Continue reading “πŸŽ„ 23/25. Calculating totals with Perl 6”

πŸŽ„ 22/25. Reversing a file with Perl 6

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”