From f98f44b2296cfcc76e76c1239b345beb6ad0ee31 Mon Sep 17 00:00:00 2001 From: Dustin Williams Date: Sun, 10 Apr 2016 01:02:19 -0700 Subject: [PATCH 1/3] Added 'example.txt' to one-liners which need file input --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e2888d3..9771f79 100644 --- a/README.md +++ b/README.md @@ -208,43 +208,43 @@ Check if a number is a prime Print the sum of all the fields on a line - perl6 -ne 'say [+] .split("\t")' + perl6 -ne 'say [+] .split("\t")' example.txt Print the sum of all the fields on all lines - perl6 -e 'say [+] lines.split("\t")' + perl6 -e 'say [+] lines.split("\t")' example.txt Shuffle all fields on a line - perl6 -ne '.split("\t").pick(*).join("\t").say' + perl6 -ne '.split("\t").pick(*).join("\t").say' example.txt Find the lexically minimum element on a line - perl6 -ne '.split("\t").min.say' + perl6 -ne '.split("\t").min.say' example.txt Find the lexically minimum element over all the lines - perl6 -e 'lines.split("\t").min.say' + perl6 -e 'lines.split("\t").min.say' example.txt Find the lexically maximum element on a line - perl6 -ne '.split("\t").max.say' + perl6 -ne '.split("\t").max.say' example.txt Find the lexically maximum element over all the lines - perl6 -e 'lines.split("\t").max.say' + perl6 -e 'lines.split("\t").max.say' example.txt Find the numerically minimum element on a line - perl6 -ne '.split("\t")».Numeric.min.say' + perl6 -ne '.split("\t")».Numeric.min.say' example.txt Find the numerically maximum element on a line - perl6 -ne '.split("\t")».Numeric.max.say' + perl6 -ne '.split("\t")».Numeric.max.say' example.txt Replace each field with its absolute value - perl6 -ne '.split("\t").map(*.abs).join("\t").say' + perl6 -ne '.split("\t").map(*.abs).join("\t").say' example.txt Find the total number of letters on each line @@ -260,17 +260,17 @@ Find the total number of elements on each line, split on a comma Find the total number of fields (words) on all lines - perl6 -e 'say lines.split("\t").elems' #fields + perl6 -e 'say lines.split("\t").elems' example.txt #fields perl6 -e 'say lines.words.elems' example.txt #words Print the total number of fields that match a pattern - perl6 -e 'say lines.split("\t").comb(/pattern/).elems' #fields - perl6 -e 'say lines.words.comb(/pattern/).elems' #words + perl6 -e 'say lines.split("\t").comb(/pattern/).elems' example.txt #fields + perl6 -e 'say lines.words.comb(/pattern/).elems' example.txt #words Print the total number of lines that match a pattern - perl6 -e 'say lines.grep(/in/).elems' + perl6 -e 'say lines.grep(/in/).elems' example.txt Print the number PI to n decimal places (e.g. 10) From 0bd11f27daa68ff6ab65c775efe2eef2c2ce2bdb Mon Sep 17 00:00:00 2001 From: Dustin Williams Date: Sun, 10 Apr 2016 01:06:45 -0700 Subject: [PATCH 2/3] RGB to HTML one-liner was just a copy of the HTML to RGB one-liner. This commit corrects that. It's not likely idiomatic Perl6, but it works until a better solution is given. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9771f79..4508615 100644 --- a/README.md +++ b/README.md @@ -659,7 +659,7 @@ Color conversion, HTML to RGB Color conversion, RGB to HTML - echo "#ffff00" | perl6 -ne '.comb(/\w\w/).map({:16($_)}).say' + echo "(255 255 0)" | perl6 -ne 'my $out = "#"; for m:g/\d+/ -> $d { $out ~= sprintf("%02x", $d.Int);}; say $out;' WWW --- From 2d68735c4cf74f9e61e8c8ae832aef066d44b1e2 Mon Sep 17 00:00:00 2001 From: Dustin Williams Date: Sun, 10 Apr 2016 01:18:44 -0700 Subject: [PATCH 3/3] Corrected GCM -> GCD (matches previous example) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4508615..eeff99b 100644 --- a/README.md +++ b/README.md @@ -322,7 +322,7 @@ Calculate greatest common divisor perl6 -e 'say [gcd] @list_of_numbers' -Calculate GCM of numbers 20 and 35 using Euclid's algorithm +Calculate GCD of numbers 20 and 35 using Euclid's algorithm perl6 -e 'say (20, 35, *%* ... 0)[*-2]'