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”
Category: Programming languages
π‘ 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”
πΊ Perl 6 One-Liners slides
Here are the slides of my talk at the German Perl Workshop 2019 in Munich, which summarises a Christmas series of posts written last year. Lots of Perl 6 one-liners and related stuff such as the usage of the MAIN function. Video recording should also appear soon. Update. The video is ready.
πΊ 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”