diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2025-11-11 23:16:48 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2025-11-11 23:16:48 +0800 |
| commit | 3b3b0b8dbde9d5d676963f86a6a4d90b6afd27f2 (patch) | |
| tree | 01cd0a2d65691aaaedca968bcd17c9ac6bb0b5c6 | |
| parent | 0f16a24e565a6f69414dd5094df8a1d3a732e457 (diff) | |
| download | perlweeklychallenge-club-3b3b0b8dbde9d5d676963f86a6a4d90b6afd27f2.tar.gz perlweeklychallenge-club-3b3b0b8dbde9d5d676963f86a6a4d90b6afd27f2.tar.bz2 perlweeklychallenge-club-3b3b0b8dbde9d5d676963f86a6a4d90b6afd27f2.zip | |
blog for challenge 347, task 1
| -rw-r--r-- | challenge-347/feng-chang/raku/ch-1.ipynb | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/challenge-347/feng-chang/raku/ch-1.ipynb b/challenge-347/feng-chang/raku/ch-1.ipynb new file mode 100644 index 0000000000..a392bc2942 --- /dev/null +++ b/challenge-347/feng-chang/raku/ch-1.ipynb @@ -0,0 +1,125 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "5ae71ca6-6570-4e52-b297-73b3e7cc38bd", + "metadata": {}, + "source": [ + "# PWC347, Task 1 Format Date\n", + "**冯昶 2025-11-11**\n", + "\n", + "Following is my ch-1.raku script:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e58308dd-1ecf-4133-a308-8a1312351782", + "metadata": {}, + "outputs": [], + "source": [ + "#!/bin/env raku\n", + "\n", + "unit sub MAIN(Str:D $s);\n", + "\n", + "my %months = <Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec> Z=> 1..12;\n", + "my ($day, $mon, $yr) = $s.words;\n", + "printf '%d-%02d-%02d', $yr, %months{$mon}, $day.substr(0,*-2);" + ] + }, + { + "cell_type": "markdown", + "id": "04af21d5-c370-44e2-ab74-a131351f0d3a", + "metadata": {}, + "source": [ + "`Z=>` is a more readable approach to defined a hash in Raku when dealing with sequences, e.g.," + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "354e4485-407c-4388-a81a-e8edb0dfc9ba", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{:a(1), :b(2), :c(3), :d(4), :e(5), :f(6), :g(7), :h(8), :i(9), :j(10), :k(11), :l(12), :m(13), :n(14), :o(15), :p(16), :q(17), :r(18), :s(19), :t(20), :u(21), :v(22), :w(23), :x(24), :y(25), :z(26)}\n" + ] + } + ], + "source": [ + "my %letters = 'a'..'z' Z=> 1..26;\n", + "put %letters.raku;" + ] + }, + { + "cell_type": "markdown", + "id": "77b9210d-046f-4b8e-ae2a-980c91e0b107", + "metadata": {}, + "source": [ + "`.words` is convienent in translate sentences into a list of words:" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "d4d36234-8ad3-4724-a750-2b7d4eb867d1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(\"`.words`\", \"is\", \"convienent\", \"in\", \"translate\", \"sentences\", \"into\", \"a\", \"list\", \"of\", \"words\").Seq\n" + ] + } + ], + "source": [ + "put '`.words` is convienent in translate sentences into a list of words'.words.raku;" + ] + }, + { + "cell_type": "markdown", + "id": "171b9af9-771f-48ce-97a4-0393d019f3ff", + "metadata": {}, + "source": [ + "`.substr(0,*-2)` cuts the last 2 characters off from a string:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "fc4815d4-52e0-4772-8c49-1098ef47bced", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "abcdefg\n" + ] + } + ], + "source": [ + "put 'abcdefgYZ'.substr(0,*-2);" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Raku", + "language": "raku", + "name": "raku" + }, + "language_info": { + "file_extension": ".raku", + "mimetype": "text/plain", + "name": "raku", + "version": "6.d" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} |
