{"@attributes":{"version":"2.0"},"channel":{"title":"Sorashi","link":"https:\/\/sorashi.dev\/","description":"Recent content on Sorashi","generator":"Hugo -- gohugo.io","language":"en-us","lastBuildDate":"Sun, 24 Oct 2021 00:00:00 +0000","item":[{"title":"The .NET Drama of PR 22217","link":"https:\/\/sorashi.dev\/net-drama\/","pubDate":"Sun, 24 Oct 2021 00:00:00 +0000","guid":"https:\/\/sorashi.dev\/net-drama\/","description":"<p>On October 20th, the PR <a class=\"link\" href=\"https:\/\/github.com\/dotnet\/sdk\/pull\/22217\" target=\"_blank\" rel=\"noopener\"\n>#22217<\/a> was\ncreated (and later merged) in the <a class=\"link\" href=\"https:\/\/github.com\/dotnet\/sdk\" target=\"_blank\" rel=\"noopener\"\n>dotnet\/sdk<\/a>\nrepository. This change, named <em>Remove Hot Reload support from dotnet watch<\/em>,\nremoved this awaited feature from the dotnet CLI and left it available only in\nVisual Studio 2022. Note that this change was done a few days before .NET 6\nrelease (releasing on 2021-11-08), removing it from this version. The PR removed\naround 2,500 lines of code from the .NET SDK.<\/p>\n<p>Microsoft explained their reasoning in a blog post called <a class=\"link\" href=\"https:\/\/devblogs.microsoft.com\/dotnet\/update-on-net-hot-reload-progress-and-visual-studio-2022-highlights\/\" target=\"_blank\" rel=\"noopener\"\n>Update on .NET Hot\nReload progress and Visual Studio 2022\nHighlights<\/a>.<\/p>\n<blockquote>\n<p>With these considerations, we&rsquo;ve decided that starting with the upcoming .NET\n6 GA release, we will enable Hot Reload functionality only through Visual\nStudio 2022 so we can focus on providing the best experiences to the most\nusers. [&hellip;] To clarify, we are not releasing Hot Reload as a feature of the\n<code>dotnet watch<\/code> tool.<\/p><\/blockquote>\n<p>This statement and removal resulted in a large backlash and discussion from the\nopen-source .NET community. The Verge covers this story with information from\nthe inside of Microsoft in their article called <a class=\"link\" href=\"https:\/\/www.theverge.com\/2021\/10\/22\/22740701\/microsoft-dotnet-hot-reload-removal-decision-open-source\" target=\"_blank\" rel=\"noopener\"\n>Microsoft angers the .NET open\nsource community with a controversial\ndecision<\/a>.\nThe main complains were that the feature should keep cross-platform support and\nnot limit it to Windows (and later Mac through VS for Mac).<\/p>\n<p>One of the protesting developer created the PR\n<a class=\"link\" href=\"https:\/\/github.com\/dotnet\/sdk\/pull\/22262\/\" target=\"_blank\" rel=\"noopener\"\n>#22262<\/a> reverting the changes. This\nPR is one of the most (if not <em>the<\/em> most) approved PR in the history of GitHub,\naccumulating 417 unique approving reviews with a total of 523 PR participants at\nthe time of writing.<\/p>\n<p>This PR was merged in around 29 hours<\/p>\n<p><img src=\"..\/net-drama-merge.png\" alt=\"PR merge\" \/><\/p>\n<p>with a follow-up blog post (<a class=\"link\" href=\"https:\/\/devblogs.microsoft.com\/dotnet\/net-hot-reload-support-via-cli\/\" target=\"_blank\" rel=\"noopener\"\n>.NET Hot Reload Support via\nCLI<\/a>)\nfrom Microsoft apologizing about the change.<\/p>\n<p>This decision was followed by another story from The Verge called <a class=\"link\" href=\"https:\/\/www.theverge.com\/2021\/10\/23\/22742282\/microsoft-dotnet-hot-reload-u-turn-response\" target=\"_blank\" rel=\"noopener\"\n>Microsoft\nreverses controversial .NET change after open source community\noutcry<\/a>.<\/p>"},{"title":"Number of zeros at the end of a factorial in logarithmic time","link":"https:\/\/sorashi.dev\/number-of-zeros-at-the-end-of-factorial-in-logarithmic-time\/","pubDate":"Mon, 21 Dec 2020 00:00:00 +0000","guid":"https:\/\/sorashi.dev\/number-of-zeros-at-the-end-of-factorial-in-logarithmic-time\/","description":"<p>You might think that knowing the number of zeros that suffix the value of $n!$\nis useless. And you might be right. At least I haven&rsquo;t thought of any use.<\/p>\n<p>Even though, I want to leave this here, because I found this out while solving\nsomething else.<\/p>\n<p>So the problem is:<\/p>\n<p><em>Given $n$, return the maximum number of zeros, that suffix $n!$. For example\nfor $n=5$, $n! = 15511210043330985984000000$, so the answer would be $6$.<\/em><\/p>\n<p>We could compute the value of the factorial and count the number of zeros. We&rsquo;d\nget the result this way in $\\mathcal O(n + \\log (n!))$ time (compute $n!$ plus\ncount the zeros), <a class=\"link\" href=\"https:\/\/math.stackexchange.com\/questions\/2152256\/big-o-notation-on-the-log-factorial\" target=\"_blank\" rel=\"noopener\"\n>which is<\/a> $\\mathcal O(n\\log (n))$.<\/p>\n<p>Let&rsquo;s use the following fact<\/p>\n<p><em>The number of zeros at the end of a number $n$ is equivalent to the number of\ntimes $n$ can be evenly divided by ten.<\/em><\/p>\n<p>So an equivalent problem to the one given above is: How many 10s can you factor\nout of $n!$.<\/p>\n<p>We could scan the numbers 1 through $n$ and find the number of 10s that get made\nwhen computing the factorial. For example, $2\\cdot 5$ makes a ten, $10$ makes a\nten, $15\\cdot 4=60$ makes a ten, $20$ makes a ten, $25*8=200$ makes two tens!\nThat&rsquo;s 6 tens in total, the answer to the example of $25!$.<\/p>\n<p>A pattern appears here. For each number $x$ in $(1\\dots n)$, sum the number of\ntimes we can divide $x$ by 5, and that&rsquo;s our result.<\/p>\n<p>$$\\sum_{x=1}^n \\max\\left(\\left\\{k\\in\\mathbb N^+\\mid x\\equiv 0\\ (\\text{mod } 5^k)\\right\\}\\cup {0}\\right)$$<\/p>\n<p>Why is that? Well, a ten is made from 2 and 5. Informally, there is so many 2s\nto pair with 5s, that <strong>we can just count the 5s<\/strong>. 5 can be paired with 2. 10 can be paired with the two in 4. The five in 15 can be paired with the second two in 4. 20 can be paired with a two in 8. And so on.<\/p>\n<p>More formally, let&rsquo;s define<\/p>\n<p>$$g(n, a):= \\sum_{x=1}^n \\max\\left(\\left\\{k\\in\\mathbb N^+\\mid x\\equiv 0\\ (\\text{mod } a^k)\\right\\}\\cup {0}\\right),,$$<\/p>\n<p>then for a given large $n$, it holds $g(n, 5)\\leq g(n, 2)$, which can be easily\nseen. Generally $a&gt;b \\iff g(n,a)\\leq g(n,b)$.<\/p>\n<p>Now how do we compute $g(n, 5)$ efficiently? A straight-forward way is to go through each number and try each $k$, that would be $\\mathcal O(n^2)$. With a more clever approach, I&rsquo;m sure this can be made $\\mathcal O(n)$.<\/p>\n<p>But let&rsquo;s think even smaller.<\/p>\n<p>I propose<\/p>\n<p>$$g(n, a) = \\sum_{i=1}^{\\lfloor \\log_a n \\rfloor}\\lfloor \\frac{n}{a^i}\\rfloor,.$$<\/p>\n<p>Why does this count the number of times we find the factor $a$ in the numbers\nfrom $1$ to $n$? Well, it takes into account all powers of $a$. First it divides\nby $a^1$, which finds how many $a$&rsquo;s there are in $n$. That includes even\nnumbers which contain $a\\cdot a$ as a factor, or $a\\cdot a \\cdot a$, and so on.\nFor each of these, it adds one to the sum.<\/p>\n<p>Next, we divide $n$ by $a^2$. This finds the number of times $a\\cdot a$ appear\nas a factor. It counts when $a\\cdot a$ or $a\\cdot a\\cdot a\\cdots$ appear, but\nnot when $a$ appears alone. For each of these it adds one to the sum. Which is\ncorrect &ndash; we already added one for the second $a$ that appears in $a\\cdot a$.<\/p>\n<p>This continues while $a^i\\leq n$. Let&rsquo;s see an example. For $g(25, 5)$, we get<\/p>\n<p>$$ \\lfloor\\frac{25}{5}\\rfloor+\\lfloor\\frac{25}{25}\\rfloor=5+1=6,. $$<\/p>\n<p>The first division counts a single five in $5, 10, 15, 20$ and $25$. The second division counts the second five in $25$.<\/p>\n<p>Our original problem is the result of $g(n,5)$. This runs in $\\mathcal O(\\log\nn)$ time. Nice.<\/p>\n<p>Now what&rsquo;s interesting and is just my unproven funny informal small conjecture (which I plan to think about later)<\/p>\n<p>$$\\sum_{i=1}^{\\lfloor \\log_a n \\rfloor}\\lfloor \\frac{n}{a^i}\\rfloor=\\lfloor \\frac{n}{a-1}\\rfloor -\\xi(n, a),,$$<\/p>\n<p>where $\\xi\\colon (\\mathbb N\\times \\mathbb N)\\to \\mathbb N$ is an unknown function, with an average\nvalue of around 5, which is not a lot. That means we have a\ngood approximation for $g(n,a)$. That one is for the engineers. Bye~<\/p>\n<p><img src=\"fig1.svg\" alt=\"Plot of xi function\" \/><\/p>"},{"title":"Asus E200HA Arch Linux Installation Guide","link":"https:\/\/sorashi.dev\/asus-e200ha-arch\/","pubDate":"Sat, 01 Feb 2020 00:00:00 +0000","guid":"https:\/\/sorashi.dev\/asus-e200ha-arch\/","description":"<h2 id=\"foreword\">Foreword<\/h2>\n<p>Oh, the Asus E200HA! A small Intel Cherry Trail netbook with 32GB of internal memory and\n2 gigs of RAM. I bought one for its compact size and small weight. Boy, was\nit a mistake. It comes with Windows 10 pre-installed and Windows 10 sure likes\nhuge updates and general littering of your drive. The device is literally unusable after a small while. That is not a huge\ndeal, you can just install Linux, right? It wasn&rsquo;t that easy. At the time I\nbought the device, Linux kernel hadn&rsquo;t integrated drivers for its network card,\naudio card and SD card reader. Some people even reported they couldn&rsquo;t get their touch-pad\nto work, or that the backlight control didn&rsquo;t work. Intel Cherry Trail CPU series\nsupport was also stuttering, because of problems with power saving - the purpose\nof Cherry Trail processors.<\/p>\n<p>Hopeless as it may seem, there are incredible people working on the Linux kernel\nevery day and fighting against the powerful wave of proprietary devices that receive drivers only for Windows (some people suggest Windows may have contracts and does this intentionally so that people don&rsquo;t use other systems, but that&rsquo;s a conspiration-sounding statement). And they eventually managed to fix these problems (by version 5.3). But user-friendly\nLinux distributions do not update their kernel until it&rsquo;s thoroughly tested. So\nthere have been\n<a class=\"link\" href=\"https:\/\/github.com\/Grippy98\/Asus-E200HA-Linux-Post-Install-Script\" target=\"_blank\" rel=\"noopener\"\n>attempts<\/a> at\ncreating a script that would update the kernel and force some new drivers to be\nused, but I never managed to make audio work using the script.<\/p>\n<p>When Ubuntu 19.04 came around, the required kernel version was built in and\nsupported. So I tried again. Audio still didn&rsquo;t work, but I <a class=\"link\" href=\"https:\/\/github.com\/heikomat\/linux\/tree\/cx2072x\/cx2072x_fixes_and_manual\" target=\"_blank\" rel=\"noopener\"\n>found out<\/a>\nthat the system isn&rsquo;t configured to use (or recognize?) the audio card. And so I finally managed to get audio working. Eventually I realized that Ubuntu is still too big of a system for this timid device. Furthermore, kernel 5.3 had some problems with the graphics chip that ships with Cherry Trail devices, making your screen freeze and forcing you to hard-reset.<\/p>\n<p>And so I decided to install Arch. Because Arch lets you install just what you want and because Arch usually has bleeding-edge kernel. And since installing Arch is not completely user-friendly I decided to make a small guide (or rather a log) specifically for this device. I don&rsquo;t guarantee it will work and I&rsquo;m not responsible for any damages you may cause to your device. It&rsquo;s actually just a record of what I did for a successful install at the time.<\/p>\n<p>Good luck and have fun!<\/p>\n<p><em>Warning: As of late February 2020 there seem to be screen freezing issues.<\/em><\/p>\n<p>Looks like <strong>Linux Mint latest edition 20 Ulyana - Cinnamon 64<\/strong> works out of the box for this device! Thank you Badd Pitt for your <a class=\"link\" href=\"http:\/\/disq.us\/p\/2d7jp8j\" target=\"_blank\" rel=\"noopener\"\n>comment<\/a>.<\/p>\n<h2 id=\"booting\">Booting<\/h2>\n<p>I used Rufus on Windows to burn <code>archlinux-2019.12.01-x86_64.iso<\/code> to a drive in ISO mode.<\/p>\n<p>Start E200HA and press F1 or F2 repeatedly until you&rsquo;re shown the BIOS menu. Move to boot options and specify the USB drive as the first option. Then save and exit.<\/p>\n<h2 id=\"first-wi-fi-connection\">First Wi-Fi connection<\/h2>\n<p>I needed to connect to eduroam (a global Wi-Fi network for educational institutions), which uses WPA-EAP. If you have access to a classic Wi-Fi, use <code>wifi-menu<\/code> to connect.<\/p>\n<ul>\n<li>To connect to eduroam, create <code>wpa_supplicant<\/code> config file: <code>vi wpa_supplicant.conf<\/code><\/li>\n<\/ul>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-text\" data-lang=\"text\"><span class=\"line\"><span class=\"cl\">ctrl_interface=\/run\/wpa_supplicant\n<\/span><\/span><span class=\"line\"><span class=\"cl\">update_config=1\n<\/span><\/span><span class=\"line\"><span class=\"cl\"># ^ these two lines may not be needed\n<\/span><\/span><span class=\"line\"><span class=\"cl\">network={\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> ssid=&#34;eduroam&#34;\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> key_mgmt=WPA-EAP\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> eap=PEAP\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> phase2=&#34;none&#34;\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> identity=&#34;*username*&#34;\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> password=&#34;*password*&#34;\n<\/span><\/span><span class=\"line\"><span class=\"cl\">}\n<\/span><\/span><\/code><\/pre><\/div><ul>\n<li>check if <code>wlan0<\/code> interface exists: <code>ip link<\/code><\/li>\n<li>see if you can connect to eduroam: <code>wpa_supplicant -i wlan0 -c wpa_supplicant.conf<\/code><\/li>\n<li>cancel the process if the connection was successful; run it in background as a daemon: <code>wpa_supplicant -B -i wlan0 -c wpa_supplicant.conf<\/code><\/li>\n<li><code>dhcpcd<\/code> to get your ip<\/li>\n<li><code>ping google.com<\/code> to check connection<\/li>\n<\/ul>\n<h2 id=\"installation\">Installation<\/h2>\n<p>Use <code>cfdisk \/dev\/mmcblk0<\/code> to create (in this order)<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-text\" data-lang=\"text\"><span class=\"line\"><span class=\"cl\">300M EFI Filesystem\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> 1G Linux swap\n<\/span><\/span><span class=\"line\"><span class=\"cl\">rest Linux filesystem\n<\/span><\/span><\/code><\/pre><\/div><div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\">mkfs.fat -F32 \/dev\/mmcblk0p1\n<\/span><\/span><span class=\"line\"><span class=\"cl\">mkswap \/dev\/mmcblk0p2\n<\/span><\/span><span class=\"line\"><span class=\"cl\">mkfs.ext4 \/dev\/mmcblk0p3\n<\/span><\/span><span class=\"line\"><span class=\"cl\">mount \/dev\/mmcblk0p3 \/mnt\n<\/span><\/span><span class=\"line\"><span class=\"cl\">swapon \/dev\/mmcblk0p2\n<\/span><\/span><\/code><\/pre><\/div><p>Edit mirrorlist to have your preferred mirrors at the top\n<code>vi \/etc\/pacman.d\/mirrorlist<\/code><\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\">pacstrap \/mnt base base-devel linux linux-firmware\n<\/span><\/span><span class=\"line\"><span class=\"cl\">genfstab -U -p \/mnt &gt;&gt; \/mnt\/etc\/fstab\n<\/span><\/span><span class=\"line\"><span class=\"cl\">arch-chroot \/mnt\n<\/span><\/span><\/code><\/pre><\/div><p>Choose a hostname<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\"><span class=\"nb\">echo<\/span> your_hostname &gt; \/etc\/hostname\n<\/span><\/span><\/code><\/pre><\/div><p>Uncomment <code>en_US.UTF-8 UTF-8<\/code> and <code>en_US ISO-8859-1<\/code><\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\">pacman -S vim\n<\/span><\/span><span class=\"line\"><span class=\"cl\">vim \/etc\/locale.gen\n<\/span><\/span><span class=\"line\"><span class=\"cl\">locale_gen\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"nb\">echo<\/span> <span class=\"nv\">LANG<\/span><span class=\"o\">=<\/span>en_US.UTF-8 &gt; \/etc\/locale.conf\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"nb\">export<\/span> <span class=\"nv\">LANG<\/span><span class=\"o\">=<\/span>en_US.UTF-8\n<\/span><\/span><\/code><\/pre><\/div><p>Find your zone in <code>\/usr\/share\/zoneinfo\/<\/code> using <code>ls<\/code> and then<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\">ln -s \/usr\/share\/zoneinfo\/Europe\/Prague \/etc\/localtime\n<\/span><\/span><span class=\"line\"><span class=\"cl\">hwclock --systohc --utc\n<\/span><\/span><span class=\"line\"><span class=\"cl\">passwd\n<\/span><\/span><span class=\"line\"><span class=\"cl\">useradd -mg users -G wheel -s \/bin\/bash your_username\n<\/span><\/span><span class=\"line\"><span class=\"cl\">passwd your_username\n<\/span><\/span><span class=\"line\"><span class=\"cl\">pacman -S dhcp dhcpcd wpa_supplicant dialog netctl sudo\n<\/span><\/span><span class=\"line\"><span class=\"cl\">vim \/etc\/sudoers <span class=\"c1\"># uncomment %wheel ALL=(ALL) ALL<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p>Now to the bootloader!<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\">pacman -S grub efibootmgr dosfstools os-prober mtools\n<\/span><\/span><span class=\"line\"><span class=\"cl\">mkdir \/boot\/EFI\n<\/span><\/span><span class=\"line\"><span class=\"cl\">mount \/dev\/mmcblk0p1 \/boot\/EFI\n<\/span><\/span><span class=\"line\"><span class=\"cl\">grub-install --target<span class=\"o\">=<\/span>x86_64-efi --bootloader-id<span class=\"o\">=<\/span>grub_uefi --recheck\n<\/span><\/span><span class=\"line\"><span class=\"cl\">grub-mkconfig -o \/boot\/grub\/grub.cfg\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"nb\">exit<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">umount -a\n<\/span><\/span><span class=\"line\"><span class=\"cl\">telinit <span class=\"m\">6<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p>After reboot:\nConnect to wifi either using wifi-menu or create a profile in \/etc\/netctl then<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\">sudo ip link _ down <span class=\"c1\"># _ is your interface, find it using ip<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">sudo netctl start profile_name\n<\/span><\/span><span class=\"line\"><span class=\"cl\">sudo dhcpcd\n<\/span><\/span><\/code><\/pre><\/div><p>Install xorg server<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\">sudo pacman -S xf86-video-intel xorg-server-xephyr\n<\/span><\/span><\/code><\/pre><\/div><p>Now install your desired display manager, desktop environment and terminal, for example<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\">pacman -S lightdm i3-gaps dmenu i3-status rxvt-unicode\n<\/span><\/span><span class=\"line\"><span class=\"cl\">sudo systemctl <span class=\"nb\">enable<\/span> lightdm\n<\/span><\/span><span class=\"line\"><span class=\"cl\">reboot\n<\/span><\/span><\/code><\/pre><\/div><p>Congratulations! Now go have fun and make your system comfortable. Be sure to comment if you found a mistake, have problems or just want to add something.<\/p>\n<hr>\n<p>What I personally installed after that:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\">pacman -S yay git ranger\n<\/span><\/span><span class=\"line\"><span class=\"cl\">yay powerline-fonts-git <span class=\"c1\"># then use &#34;DejaVu Sans Mono for Powerline&#34; font in your terminal<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">yay rxvt-unicode-pixbuf\n<\/span><\/span><\/code><\/pre><\/div><p>I might add other things later \ud83d\ude42<\/p>"},{"title":"How to fix Facebook archive JSON encoding","link":"https:\/\/sorashi.dev\/fix-facebook-json-archive-encoding\/","pubDate":"Fri, 13 Sep 2019 00:00:00 +0000","guid":"https:\/\/sorashi.dev\/fix-facebook-json-archive-encoding\/","description":"<p>Facebook has a great feature which allows you to download an archive of your data. This includes content of messages from Messenger, posts, photos and videos, comments etc.<\/p>\n<p>This allows you to display interesting statistics if you can work with JSON in a programming language. For example, whom did you message the most in the last 30 days? Who of your friends writes the longest messages? Imagination is your only limit.<\/p>\n<p>To request an archive of your messages follow these image clues (from Facebook settings):<\/p>\n<p><img src=\"https:\/\/i.imgur.com\/36BOBKr.png\" alt=\"Image clue 1\" \/><\/p>\n<p><img src=\"https:\/\/i.imgur.com\/Uun4uJe.png\" alt=\"Image clue 2\" \/><\/p>\n<p>You might see a problem after you download your archive and load it in your script\/program though. If you have any Unicode characters in your data Facebook&rsquo;s JSON strings will get corrupted when you parse them. It took me longer than it should to find out what&rsquo;s going on. And that&rsquo;s why I write this article - in hope to help others who find themselves in this situation.<\/p>\n<h2 id=\"whats-going-on\">What&rsquo;s going on<\/h2>\n<p>Facebook apparently represents UTF-8 characters in a broken way. Instead of outputting one <code>\\u<\/code> escape sequence for each Unicode character, Facebook actually outputs two or more in their JSON strings. An example of a Unicode character in a Facebook JSON file is <code>\\u00c5\\u0099<\/code>. This is supposed to be a single character <code>\\u0159<\/code> or Latin Small Letter R with Caron - <code>\u0159<\/code>. So what&rsquo;s going on? It&rsquo;s simple - Facebook doesn&rsquo;t understand Unicode as a single character, but rather as separate bytes. In our case the bytes <code>c5 99<\/code> in hexadecimal.<\/p>\n<p>The problem is that when Facebook puts <code>\\u00c5\\u0099<\/code> in a JSON string, most JSON prasers understand that as two Unicode characters. That&rsquo;s because the escape sequence <code>\\u00c5<\/code> is actually the Unicode code for <code>\u00c5<\/code> and <code>\\u0099<\/code> is a Unicode control character. <code>\u00c5<\/code> is represented as two bytes in a proper UTF-8 file - <code>c3 85<\/code> in hexadecimal. Same for <code>\\u0099<\/code> - two bytes - <code>c2 99<\/code>.<\/p>\n<p>In other words Facebook meant to output two single bytes, but ended up outputting the Unicode characters with their respective Unicode numbers being the bytes&rsquo; values in hexadecimal, which is actually four bytes in total. That is totally wrong and doesn&rsquo;t make any sense at all! I hope Facebook realizes this soon and fixes it so others don&rsquo;t have to enjoy this great experience of additional trouble.<\/p>\n<p>So when Facebook says <code>\\u00c5\\u0099<\/code> they actually mean two separate bytes - <code>c5 99<\/code>. That is the byte sequence for the Unicode character <code>\\u0159<\/code> - <code>\u0159<\/code>.<\/p>\n<h2 id=\"how-to-fix-that\">How to fix that<\/h2>\n<p>Use Regex to find all <code>\\u00hh<\/code> sequences and replace them with the byte with the value of <code>hh<\/code>. The regex:<\/p>\n<pre tabindex=\"0\"><code class=\"language-regex\" data-lang=\"regex\">\\\\u00([a-f0-9]{2})\n<\/code><\/pre><p>Here is a <strong>Ruby<\/strong> script which fixes all JSON files in your message inbox. Then outputs the result.<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-ruby\" data-lang=\"ruby\"><span class=\"line\"><span class=\"cl\"><span class=\"n\">path<\/span> <span class=\"o\">=<\/span> <span class=\"s1\">&#39;..\/messages\/inbox&#39;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"no\">Dir<\/span><span class=\"o\">[<\/span><span class=\"s2\">&#34;<\/span><span class=\"si\">#{<\/span><span class=\"n\">path<\/span><span class=\"o\">.<\/span><span class=\"n\">sub<\/span><span class=\"p\">(<\/span><span class=\"s1\">&#39;[\\\\\/]$&#39;<\/span><span class=\"p\">,<\/span> <span class=\"s1\">&#39;&#39;<\/span><span class=\"p\">)<\/span><span class=\"si\">}<\/span><span class=\"s2\">\/**\/message_1.json&#34;<\/span><span class=\"o\">].<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"n\">each<\/span><span class=\"p\">{<\/span><span class=\"o\">|<\/span><span class=\"n\">file<\/span><span class=\"o\">|<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"no\">File<\/span><span class=\"o\">.<\/span><span class=\"n\">write<\/span><span class=\"p\">(<\/span><span class=\"n\">file<\/span><span class=\"p\">,<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"no\">File<\/span><span class=\"o\">.<\/span><span class=\"n\">read<\/span><span class=\"p\">(<\/span><span class=\"n\">file<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"o\">.<\/span><span class=\"n\">gsub<\/span><span class=\"p\">(<\/span><span class=\"sr\">\/\\\\u00([a-f0-9]{2})\/<\/span><span class=\"p\">)<\/span> <span class=\"p\">{<\/span><span class=\"o\">|<\/span><span class=\"n\">m<\/span><span class=\"o\">|<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"vg\">$1<\/span><span class=\"o\">.<\/span><span class=\"n\">to_i<\/span><span class=\"p\">(<\/span><span class=\"mi\">16<\/span><span class=\"p\">)<\/span><span class=\"o\">.<\/span><span class=\"n\">chr<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"p\">}<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"nb\">puts<\/span> <span class=\"s2\">&#34;Done <\/span><span class=\"si\">#{<\/span><span class=\"n\">file<\/span><span class=\"si\">}<\/span><span class=\"s2\">&#34;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"p\">}<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p>Snippet for <strong>PHP<\/strong>, which fixes all occurrences in <code>$your_input_text<\/code> and <code>echo<\/code>es the result.<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-php\" data-lang=\"php\"><span class=\"line\"><span class=\"cl\"><span class=\"k\">function<\/span> <span class=\"nf\">replace_with_byte<\/span><span class=\"p\">(<\/span><span class=\"nv\">$match<\/span><span class=\"p\">)<\/span> <span class=\"p\">{<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"k\">return<\/span> <span class=\"nx\">chr<\/span><span class=\"p\">(<\/span><span class=\"nx\">hexdec<\/span><span class=\"p\">(<\/span><span class=\"nv\">$match<\/span><span class=\"p\">[<\/span><span class=\"mi\">1<\/span><span class=\"p\">]));<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"p\">}<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">echo<\/span> <span class=\"nx\">preg_replace_callback<\/span><span class=\"p\">(<\/span><span class=\"s1\">&#39;\/\\\\\\\\u00([a-f0-9]{2})\/&#39;<\/span><span class=\"p\">,<\/span> <span class=\"s1\">&#39;replace_with_byte&#39;<\/span><span class=\"p\">,<\/span> <span class=\"nv\">$your_input_text<\/span><span class=\"p\">);<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p><strong>Python<\/strong> version (might need some performance improvements):<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-python\" data-lang=\"python\"><span class=\"line\"><span class=\"cl\"><span class=\"kn\">import<\/span> <span class=\"nn\">re<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"n\">text<\/span> <span class=\"o\">=<\/span> <span class=\"s2\">&#34;This is some text with the letter <\/span><span class=\"se\">\\\\<\/span><span class=\"s2\">u00c5<\/span><span class=\"se\">\\\\<\/span><span class=\"s2\">u0099 inside&#34;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"n\">replaced<\/span> <span class=\"o\">=<\/span> <span class=\"n\">re<\/span><span class=\"o\">.<\/span><span class=\"n\">sub<\/span><span class=\"p\">(<\/span><span class=\"sa\">r<\/span><span class=\"s1\">&#39;<\/span><span class=\"se\">\\\\<\/span><span class=\"s1\">u00([a-f0-9]<\/span><span class=\"si\">{2}<\/span><span class=\"s1\">)&#39;<\/span><span class=\"p\">,<\/span> <span class=\"k\">lambda<\/span> <span class=\"n\">x<\/span><span class=\"p\">:<\/span> <span class=\"nb\">chr<\/span><span class=\"p\">(<\/span><span class=\"nb\">int<\/span><span class=\"p\">(<\/span><span class=\"n\">x<\/span><span class=\"o\">.<\/span><span class=\"n\">group<\/span><span class=\"p\">(<\/span><span class=\"mi\">1<\/span><span class=\"p\">),<\/span> <span class=\"mi\">16<\/span><span class=\"p\">)),<\/span> <span class=\"n\">text<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"nb\">print<\/span><span class=\"p\">(<\/span><span class=\"nb\">repr<\/span><span class=\"p\">(<\/span><span class=\"n\">replaced<\/span><span class=\"p\">))<\/span> <span class=\"c1\"># &#39;This is some text with the letter \u00c5\\x99 inside&#39;<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"n\">buffer<\/span> <span class=\"o\">=<\/span> <span class=\"p\">[<\/span><span class=\"nb\">ord<\/span><span class=\"p\">(<\/span><span class=\"n\">c<\/span><span class=\"p\">)<\/span> <span class=\"k\">for<\/span> <span class=\"n\">c<\/span> <span class=\"ow\">in<\/span> <span class=\"n\">replaced<\/span><span class=\"p\">]<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"n\">result<\/span> <span class=\"o\">=<\/span> <span class=\"nb\">bytes<\/span><span class=\"p\">(<\/span><span class=\"n\">buffer<\/span><span class=\"p\">)<\/span><span class=\"o\">.<\/span><span class=\"n\">decode<\/span><span class=\"p\">(<\/span><span class=\"s1\">&#39;utf-8&#39;<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"nb\">print<\/span><span class=\"p\">(<\/span><span class=\"n\">result<\/span><span class=\"p\">)<\/span> <span class=\"c1\"># This is some text with the letter \u0159 inside<\/span>\n<\/span><\/span><\/code><\/pre><\/div>"},{"title":"(CZ) Line\u00e1rn\u00ed diofantick\u00e9 rovnice","link":"https:\/\/sorashi.dev\/linear-diophantine-equations\/","pubDate":"Sun, 27 Jan 2019 00:00:00 +0000","guid":"https:\/\/sorashi.dev\/linear-diophantine-equations\/","description":"<p>Diofantick\u00e9 rovnice jsou <span class=\"hint\" title=\"maj\u00edc\u00ed v\u00edce nezn\u00e1m\u00fdch, ne\u017e rovnost\u00ed\">podur\u010den\u00e9<\/span> polynomi\u00e1ln\u00ed rovnice, u kter\u00fdch se hled\u00e1\n\u0159e\u0161en\u00ed v mno\u017ein\u011b $\\mathbb{Z}$.<\/p>\n<p>Line\u00e1rn\u00ed diofantick\u00e1 rovnice je rovnice ve tvaru sou\u010dtu dvou monom\u016f prvn\u00edho \u0159\u00e1du:<\/p>\n<p>$$ax+by=c\\,.$$<\/p>\n<p>Takov\u00fdm rovnostem se tak\u00e9 \u0159\u00edk\u00e1 <a class=\"link\" href=\"https:\/\/cs.wikipedia.org\/wiki\/B%C3%A9zoutova_rovnost\" target=\"_blank\" rel=\"noopener\"\n>B\u00e9zoutovy<\/a>. Lze je vy\u0159e\u0161it pomoc\u00ed <a class=\"link\" href=\"https:\/\/cs.wikipedia.org\/wiki\/Roz%C5%A1%C3%AD%C5%99en%C3%BD_Eukleid%C5%AFv_algoritmus\" target=\"_blank\" rel=\"noopener\"\n>roz\u0161\u00ed\u0159en\u00e9ho Euklidova algoritmu<\/a>.<\/p>\n<p>K \u010demu se ale \u0159e\u0161en\u00ed takov\u00fdch rovnic hod\u00ed? Poj\u010fme se pod\u00edvat na jednu \u00falohu,\nkter\u00e1 se objevila v matematick\u00e9m testu pro \u010dtvrtou t\u0159\u00eddu z\u00e1kladn\u00ed \u0161koly.<\/p>\n<blockquote>\n<p>Mimoni zalo\u017eili orchestr. Um\u00ed hr\u00e1t jen na basu nebo kytaru. Jejich basy maj\u00ed 5 strun a jejich kytary maj\u00ed 6 strun. Celkem maj\u00ed n\u00e1stroje v jejich orchestru 39 strun. Kolik Mimo\u0148\u016f hraje v orchestru?<\/p><\/blockquote>\n<p>Po p\u0159e\u010dten\u00ed by m\u011bl b\u00fdt ka\u017ed\u00fd schopen p\u0159ev\u00e9st slovn\u00ed vyj\u00e1d\u0159en\u00ed do matematick\u00e9 notace<\/p>\n<p>$$5x+6y=39\\,.$$<\/p>\n<p>\u017d\u00e1ci \u010dtvrt\u00e9 t\u0159\u00eddy v\u011bt\u0161inou neznaj\u00ed roz\u0161\u00ed\u0159en\u00fd Euklid\u016fv algoritmus. Na\u0161t\u011bst\u00ed jsou\nzde mal\u00e9 koeficienty a s trochou pokusu a omylu by m\u011bli p\u0159ij\u00edt na to, \u017ee \u0159e\u0161en\u00edm\nje $[x;y]=[3;4]$, neboli Mimo\u0148\u016f hraje v orchestru 7.<\/p>\n<p>Poj\u010fme si ale uk\u00e1zat, jak by vypadalo obecn\u00e9 \u0159e\u0161en\u00ed, kter\u00e9 lze aplikovat na\npodobn\u00e9 \u00falohy pro jak\u00e1koli \u010d\u00edsla $a, b, c\\in \\mathbb{Z}$.<\/p>\n<p><a class=\"link\" href=\"https:\/\/cs.wikipedia.org\/wiki\/B%C3%A9zoutova_rovnost\" target=\"_blank\" rel=\"noopener\"\n>B\u00e9zoutova rovnost<\/a> \u0159\u00edk\u00e1,\n\u017ee:<\/p>\n<p><em>Nech\u0165 $c:=gcd(x,y)$, potom:<\/em><\/p>\n<p>$$\\forall x,y\\in\\mathbb{Z}\\ \\exists a,b\\in\\mathbb{Z}\\colon ax+by=c\\,.$$<\/p>\n<p>Jeliko\u017e $gcd(5,6)=1$, na\u0161e rovnice m\u00e1 celo\u010d\u00edseln\u00e1 \u0159e\u0161en\u00ed. Abychom je zjistili, mus\u00edme\nnejd\u0159\u00edve nal\u00e9zt \u0159e\u0161en\u00ed pro $5x+6y=gcd(5,6)=1$. K tomu lze vyu\u017e\u00edt <a class=\"link\" href=\"https:\/\/cs.wikipedia.org\/wiki\/Eukleid%C5%AFv_algoritmus\" target=\"_blank\" rel=\"noopener\"\n>Euklid\u016fv algoritmus<\/a>.<\/p>\n<ol>\n<li>$6=5(1)+1$<\/li>\n<li>$5=1(5)+0$<\/li>\n<\/ol>\n<p>Zp\u011btn\u00fdm dosazen\u00edm zjist\u00edme, \u017ee\n$5(-1)+6(1)=1$. U tohoto trivi\u00e1ln\u00edho p\u0159\u00edkladu je to z\u0159ejm\u00e9, ale u slo\u017eit\u011bj\u0161\u00edch verz\u00ed\nje zp\u011btn\u00e9 dosazov\u00e1n\u00ed del\u0161\u00ed. Toto dosazov\u00e1n\u00ed je pr\u00e1v\u011b <em>roz\u0161\u00ed\u0159en\u00edm<\/em> Euklidova algoritmu.<\/p>\n<p>Nyn\u00ed, kdy\u017e jsme nalezli \u0159e\u0161en\u00ed pro $5x+6y=1$, jednodu\u0161e vyn\u00e1sob\u00edme celou rovnici tak,\nabychom na prav\u00e9 stran\u011b dostali po\u017eadovan\u00e9 $c$. V na\u0161em p\u0159\u00edpad\u011b 39.<\/p>\n<p>$$5(-39)+6(39)=39$$<\/p>\n<p>Z\u00edskali jsme tak jedno z \u0159e\u0161en\u00ed $[x_1;y_1]=[-39;39]\\in K$. V\u0161echna ostatn\u00ed \u0159e\u0161en\u00ed maj\u00ed\nn\u00e1sleduj\u00edc\u00ed tvar:<\/p>\n<p>$$\\bigg[x_1-r\\frac{b}{gcd(a,b)}; y_1+r\\frac{a}{gcd(a,b)}\\bigg]\\in K; r\\in \\mathbb{Z}\\,,\\\\ [-39-6r;39+5r]\\in K; r\\in \\mathbb{Z}\\,.$$<\/p>\n<p>Pro vy\u0159e\u0161en\u00ed p\u016fvodn\u00ed \u00falohy mus\u00edme nal\u00e9zt uspo\u0159\u00e1danou dvojici $[x;y]$ takovou, \u017ee $x&gt;0\\wedge y&gt;0$. Toho lze jednodu\u0161e dos\u00e1hnout nerovnicemi.<\/p>\n<p>$$-39-6r&gt;0 \\wedge 39+5r&gt;0\\,,\\\\ r&lt;-\\frac{13}{2} \\wedge r&gt;-\\frac{39}{5}\\,,\\\\ r&lt;-6,5\\wedge r&gt;-7,8\\,.$$<\/p>\n<p>Jedin\u00e9 cel\u00e9 \u010d\u00edslo vyhovuj\u00edc\u00ed t\u00e9to nerovnici je $r=-7$. Po dosazen\u00ed $r$ do vzorce dost\u00e1v\u00e1me\n$[x;y]=[3;4]$.<\/p>\n<hr>\n<p>Proto\u017ee se jedn\u00e1 o algoritmus, jeho manu\u00e1ln\u00ed exekuce je n\u00e1chyln\u00e1 na chyby a \u010dasto tak\u00e9 f\u00e1dn\u00ed. Mnohem v\u00fdhodn\u011bj\u0161\u00ed je implementovat pro tento \u00fa\u010del skript. N\u00ed\u017ee m\u016f\u017eete vid\u011bt m\u00e9 \u0159e\u0161en\u00ed v Pythonu. Pokud m\u00e1te n\u011bjak\u00e9 n\u00e1pady na jeho vylep\u0161en\u00ed, m\u016f\u017eete\nnav\u0161t\u00edvit <a class=\"link\" href=\"https:\/\/github.com\/sorashi\/linear-diophantine-equation-solver\" target=\"_blank\" rel=\"noopener\"\n>tento repozit\u00e1\u0159<\/a> na GitHubu.<\/p>\n<div class=\"highlight\"><div class=\"chroma\">\n<table class=\"lntable\"><tr><td class=\"lntd\">\n<pre tabindex=\"0\" class=\"chroma\"><code><span class=\"lnt\"> 1\n<\/span><span class=\"lnt\"> 2\n<\/span><span class=\"lnt\"> 3\n<\/span><span class=\"lnt\"> 4\n<\/span><span class=\"lnt\"> 5\n<\/span><span class=\"lnt\"> 6\n<\/span><span class=\"lnt\"> 7\n<\/span><span class=\"lnt\"> 8\n<\/span><span class=\"lnt\"> 9\n<\/span><span class=\"lnt\">10\n<\/span><span class=\"lnt\">11\n<\/span><span class=\"lnt\">12\n<\/span><span class=\"lnt\">13\n<\/span><span class=\"lnt\">14\n<\/span><span class=\"lnt\">15\n<\/span><span class=\"lnt\">16\n<\/span><span class=\"lnt\">17\n<\/span><span class=\"lnt\">18\n<\/span><span class=\"lnt\">19\n<\/span><span class=\"lnt\">20\n<\/span><span class=\"lnt\">21\n<\/span><span class=\"lnt\">22\n<\/span><span class=\"lnt\">23\n<\/span><span class=\"lnt\">24\n<\/span><span class=\"lnt\">25\n<\/span><span class=\"lnt\">26\n<\/span><span class=\"lnt\">27\n<\/span><span class=\"lnt\">28\n<\/span><span class=\"lnt\">29\n<\/span><span class=\"lnt\">30\n<\/span><\/code><\/pre><\/td>\n<td class=\"lntd\">\n<pre tabindex=\"0\" class=\"chroma\"><code class=\"language-python\" data-lang=\"python\"><span class=\"line\"><span class=\"cl\"><span class=\"k\">def<\/span> <span class=\"nf\">gcd<\/span><span class=\"p\">(<\/span><span class=\"n\">a<\/span><span class=\"p\">,<\/span> <span class=\"n\">b<\/span><span class=\"p\">):<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"k\">return<\/span> <span class=\"n\">a<\/span> <span class=\"k\">if<\/span> <span class=\"n\">b<\/span> <span class=\"o\">==<\/span> <span class=\"mi\">0<\/span> <span class=\"k\">else<\/span> <span class=\"n\">gcd<\/span><span class=\"p\">(<\/span><span class=\"n\">b<\/span><span class=\"p\">,<\/span> <span class=\"n\">a<\/span><span class=\"o\">%<\/span><span class=\"n\">b<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">def<\/span> <span class=\"nf\">xgcd<\/span><span class=\"p\">(<\/span><span class=\"n\">a<\/span><span class=\"p\">,<\/span> <span class=\"n\">b<\/span><span class=\"p\">):<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"n\">x0<\/span><span class=\"p\">,<\/span> <span class=\"n\">x1<\/span><span class=\"p\">,<\/span> <span class=\"n\">y0<\/span><span class=\"p\">,<\/span> <span class=\"n\">y1<\/span> <span class=\"o\">=<\/span> <span class=\"mi\">0<\/span><span class=\"p\">,<\/span> <span class=\"mi\">1<\/span><span class=\"p\">,<\/span> <span class=\"mi\">1<\/span><span class=\"p\">,<\/span> <span class=\"mi\">0<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"k\">while<\/span> <span class=\"n\">a<\/span> <span class=\"o\">!=<\/span> <span class=\"mi\">0<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"n\">q<\/span><span class=\"p\">,<\/span> <span class=\"n\">b<\/span><span class=\"p\">,<\/span> <span class=\"n\">a<\/span> <span class=\"o\">=<\/span> <span class=\"n\">b<\/span> <span class=\"o\">\/\/<\/span> <span class=\"n\">a<\/span><span class=\"p\">,<\/span> <span class=\"n\">a<\/span><span class=\"p\">,<\/span> <span class=\"n\">b<\/span> <span class=\"o\">%<\/span> <span class=\"n\">a<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"n\">y0<\/span><span class=\"p\">,<\/span> <span class=\"n\">y1<\/span> <span class=\"o\">=<\/span> <span class=\"n\">y1<\/span><span class=\"p\">,<\/span> <span class=\"n\">y0<\/span> <span class=\"o\">-<\/span> <span class=\"n\">q<\/span> <span class=\"o\">*<\/span> <span class=\"n\">y1<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"n\">x0<\/span><span class=\"p\">,<\/span> <span class=\"n\">x1<\/span> <span class=\"o\">=<\/span> <span class=\"n\">x1<\/span><span class=\"p\">,<\/span> <span class=\"n\">x0<\/span> <span class=\"o\">-<\/span> <span class=\"n\">q<\/span> <span class=\"o\">*<\/span> <span class=\"n\">x1<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"k\">return<\/span> <span class=\"n\">b<\/span><span class=\"p\">,<\/span> <span class=\"n\">x0<\/span><span class=\"p\">,<\/span> <span class=\"n\">y0<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">def<\/span> <span class=\"nf\">diophantine_values<\/span><span class=\"p\">(<\/span><span class=\"n\">r<\/span><span class=\"p\">,<\/span> <span class=\"n\">g<\/span><span class=\"p\">,<\/span> <span class=\"n\">a<\/span><span class=\"p\">,<\/span> <span class=\"n\">b<\/span><span class=\"p\">,<\/span> <span class=\"n\">x1<\/span><span class=\"p\">,<\/span> <span class=\"n\">y1<\/span><span class=\"p\">):<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"k\">return<\/span> <span class=\"p\">(<\/span><span class=\"n\">x1<\/span><span class=\"o\">-<\/span><span class=\"n\">r<\/span><span class=\"o\">*<\/span><span class=\"n\">b<\/span><span class=\"o\">\/<\/span><span class=\"n\">g<\/span><span class=\"p\">,<\/span><span class=\"n\">y1<\/span><span class=\"o\">+<\/span><span class=\"n\">r<\/span><span class=\"o\">*<\/span><span class=\"n\">a<\/span><span class=\"o\">\/<\/span><span class=\"n\">g<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\">\n<\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"k\">if<\/span> <span class=\"vm\">__name__<\/span> <span class=\"o\">==<\/span> <span class=\"s2\">&#34;__main__&#34;<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"nb\">print<\/span><span class=\"p\">(<\/span><span class=\"n\">gcd<\/span><span class=\"p\">(<\/span><span class=\"mi\">24<\/span><span class=\"p\">,<\/span><span class=\"mi\">16<\/span><span class=\"p\">))<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"nb\">print<\/span><span class=\"p\">(<\/span><span class=\"s2\">&#34;Linear diophantine equation input form ax+by=c&#34;<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"n\">a<\/span><span class=\"p\">,<\/span><span class=\"n\">b<\/span><span class=\"p\">,<\/span><span class=\"n\">c<\/span> <span class=\"o\">=<\/span> <span class=\"p\">[<\/span><span class=\"nb\">int<\/span><span class=\"p\">(<\/span><span class=\"nb\">input<\/span><span class=\"p\">(<\/span><span class=\"n\">x<\/span><span class=\"o\">+<\/span><span class=\"s2\">&#34;=&#34;<\/span><span class=\"p\">))<\/span> <span class=\"k\">for<\/span> <span class=\"n\">x<\/span> <span class=\"ow\">in<\/span> <span class=\"s2\">&#34;abc&#34;<\/span><span class=\"p\">]<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"n\">g<\/span><span class=\"p\">,<\/span> <span class=\"n\">x<\/span><span class=\"p\">,<\/span> <span class=\"n\">y<\/span> <span class=\"o\">=<\/span> <span class=\"n\">xgcd<\/span><span class=\"p\">(<\/span><span class=\"n\">a<\/span><span class=\"p\">,<\/span><span class=\"n\">b<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"k\">if<\/span> <span class=\"n\">g<\/span> <span class=\"o\">%<\/span> <span class=\"n\">c<\/span> <span class=\"o\">!=<\/span> <span class=\"mi\">0<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"nb\">print<\/span><span class=\"p\">(<\/span><span class=\"s2\">&#34;There are no solutions&#34;<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"n\">k<\/span> <span class=\"o\">=<\/span> <span class=\"n\">c<\/span> <span class=\"o\">\/<\/span> <span class=\"n\">g<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"n\">x<\/span><span class=\"o\">*=<\/span><span class=\"n\">k<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"n\">y<\/span><span class=\"o\">*=<\/span><span class=\"n\">k<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"nb\">print<\/span><span class=\"p\">(<\/span><span class=\"s2\">&#34;Solution for r=0:&#34;<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"nb\">print<\/span><span class=\"p\">(<\/span><span class=\"n\">diophantine_values<\/span><span class=\"p\">(<\/span><span class=\"mi\">0<\/span><span class=\"p\">,<\/span><span class=\"n\">g<\/span><span class=\"p\">,<\/span><span class=\"n\">a<\/span><span class=\"p\">,<\/span><span class=\"n\">b<\/span><span class=\"p\">,<\/span><span class=\"n\">x<\/span><span class=\"p\">,<\/span><span class=\"n\">y<\/span><span class=\"p\">))<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"k\">while<\/span> <span class=\"kc\">True<\/span><span class=\"p\">:<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"n\">r<\/span><span class=\"o\">=<\/span><span class=\"nb\">int<\/span><span class=\"p\">(<\/span><span class=\"nb\">input<\/span><span class=\"p\">(<\/span><span class=\"s2\">&#34;r=&#34;<\/span><span class=\"p\">))<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"nb\">print<\/span><span class=\"p\">(<\/span><span class=\"s2\">&#34;Solution for r=&#34;<\/span> <span class=\"o\">+<\/span> <span class=\"nb\">str<\/span><span class=\"p\">(<\/span><span class=\"n\">r<\/span><span class=\"p\">)<\/span> <span class=\"o\">+<\/span> <span class=\"s2\">&#34;:&#34;<\/span><span class=\"p\">)<\/span>\n<\/span><\/span><span class=\"line\"><span class=\"cl\"> <span class=\"nb\">print<\/span><span class=\"p\">(<\/span><span class=\"n\">diophantine_values<\/span><span class=\"p\">(<\/span><span class=\"n\">r<\/span><span class=\"p\">,<\/span><span class=\"n\">g<\/span><span class=\"p\">,<\/span><span class=\"n\">a<\/span><span class=\"p\">,<\/span><span class=\"n\">b<\/span><span class=\"p\">,<\/span><span class=\"n\">x<\/span><span class=\"p\">,<\/span><span class=\"n\">y<\/span><span class=\"p\">))<\/span>\n<\/span><\/span><\/code><\/pre><\/td><\/tr><\/table>\n<\/div>\n<\/div>"},{"title":"A comprehensive list of Rikai extensions","link":"https:\/\/sorashi.dev\/comprehensive-list-of-rikai-extensions\/","pubDate":"Wed, 05 Dec 2018 00:00:00 +0000","guid":"https:\/\/sorashi.dev\/comprehensive-list-of-rikai-extensions\/","description":"<p>There are so many rikai extensions that I got lost when I was trying to find my choice.\nI want this to be the go-to article for people who seek not only the full list of rikai\nextensions, but also the truth behind their origin.<\/p>\n<p>We&rsquo;ll begin with what you&rsquo;re all here for:<\/p>\n<table>\n<thead>\n<tr>\n<th>Name<\/th>\n<th>Browser<\/th>\n<th>Repository<\/th>\n<th>Site<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>nazeka<\/td>\n<td><a class=\"link\" href=\"https:\/\/addons.mozilla.org\/cs\/firefox\/addon\/nazeka\/\" target=\"_blank\" rel=\"noopener\"\n>Firefox<\/a>, works on Android<\/td>\n<td><a class=\"link\" href=\"https:\/\/github.com\/wareya\/nazeka\" target=\"_blank\" rel=\"noopener\"\n>GitHub<\/a><\/td>\n<td>None<\/td>\n<\/tr>\n<tr>\n<td>10ten Japanese Reader (formerly Rikaichamp)<\/td>\n<td><a class=\"link\" href=\"https:\/\/addons.mozilla.org\/en-US\/firefox\/addon\/10ten-ja-reader\/\" target=\"_blank\" rel=\"noopener\"\n>Firefox<\/a>, <a class=\"link\" href=\"https:\/\/chrome.google.com\/webstore\/detail\/10ten-japanese-reader-rik\/pnmaklegiibbioifkmfkgpfnmdehdfan\" target=\"_blank\" rel=\"noopener\"\n>Chrome<\/a>, <a class=\"link\" href=\"https:\/\/apps.apple.com\/app\/10ten-japanese-reader\/id1573540634\" target=\"_blank\" rel=\"noopener\"\n>Safari, iOS, macOS<\/a><\/td>\n<td><a class=\"link\" href=\"https:\/\/github.com\/birchill\/10ten-ja-reader\" target=\"_blank\" rel=\"noopener\"\n>GitHub<\/a><\/td>\n<td><a class=\"link\" href=\"https:\/\/twitter.com\/10tenstudy\" target=\"_blank\" rel=\"noopener\"\n>Twitter<\/a><\/td>\n<\/tr>\n<tr>\n<td>rikaichan<\/td>\n<td><a class=\"link\" href=\"https:\/\/chrome.google.com\/webstore\/detail\/rikaichan\/clidkjbfdlffpbbhlalnkifiehenkjaj?hl=en\" target=\"_blank\" rel=\"noopener\"\n>Chrome<\/a> &amp; <a class=\"link\" href=\"https:\/\/addons.mozilla.org\/firefox\/addon\/rikaichan\/\" target=\"_blank\" rel=\"noopener\"\n>Firefox<\/a><\/td>\n<td><a class=\"link\" href=\"https:\/\/github.com\/Kalamandea\/Rikaichan\" target=\"_blank\" rel=\"noopener\"\n>GitHub<\/a><\/td>\n<td>None<\/td>\n<\/tr>\n<tr>\n<td>rikaikun<\/td>\n<td><a class=\"link\" href=\"https:\/\/chrome.google.com\/webstore\/detail\/rikaikun\/jipdnfibhldikgcjhfnomkfpcebammhp?hl=en\" target=\"_blank\" rel=\"noopener\"\n>Chrome<\/a><\/td>\n<td><a class=\"link\" href=\"https:\/\/github.com\/melink14\/rikaikun\" target=\"_blank\" rel=\"noopener\"\n>GitHub<\/a><\/td>\n<td>None<\/td>\n<\/tr>\n<tr>\n<td>RikaiRebuilt<\/td>\n<td><a class=\"link\" href=\"https:\/\/chrome.google.com\/webstore\/detail\/rikairebuilt\/bhcfpccmjdpjejaahbblpnikkejnkfcj\" target=\"_blank\" rel=\"noopener\"\n>Chrome<\/a> &amp; <a class=\"link\" href=\"https:\/\/addons.mozilla.org\/cs\/firefox\/addon\/rikairebuilt\/\" target=\"_blank\" rel=\"noopener\"\n>Firefox<\/a><\/td>\n<td><a class=\"link\" href=\"https:\/\/github.com\/Garethp\/RikaiRebuilt\" target=\"_blank\" rel=\"noopener\"\n>GitHub<\/a><\/td>\n<td>None<\/td>\n<\/tr>\n<tr>\n<td>Rikaisama<\/td>\n<td><a class=\"link\" href=\"https:\/\/sourceforge.net\/projects\/rikaisama\/files\/\" target=\"_blank\" rel=\"noopener\"\n>Firefox<\/a> (XPI, not published on Firefox addon site)<\/td>\n<td>None<\/td>\n<td><a class=\"link\" href=\"http:\/\/rikaisama.sourceforge.net\/\" target=\"_blank\" rel=\"noopener\"\n>Yes<\/a><\/td>\n<\/tr>\n<tr>\n<td>rikaiXUL<\/td>\n<td>N\/A<\/td>\n<td>N\/A<\/td>\n<td><a class=\"link\" href=\"http:\/\/rikaixul.mozdev.org\/\" target=\"_blank\" rel=\"noopener\"\n>mozdev<\/a><\/td>\n<\/tr>\n<tr>\n<td>Yomichan<\/td>\n<td><a class=\"link\" href=\"https:\/\/chrome.google.com\/webstore\/detail\/yomichan\/ogmnaimimemjmbakcfefmnahgdfhfami\" target=\"_blank\" rel=\"noopener\"\n>Chrome<\/a> &amp; <a class=\"link\" href=\"https:\/\/addons.mozilla.org\/en-US\/firefox\/addon\/yomichan\/\" target=\"_blank\" rel=\"noopener\"\n>Firefox<\/a><\/td>\n<td><a class=\"link\" href=\"https:\/\/github.com\/FooSoft\/yomichan\" target=\"_blank\" rel=\"noopener\"\n>GitHub<\/a><\/td>\n<td><a class=\"link\" href=\"https:\/\/foosoft.net\/projects\/yomichan\/\" target=\"_blank\" rel=\"noopener\"\n>Yes<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Now some information about some of them:<\/p>\n<p><strong>nazeka<\/strong> is a rikai replacement with many interesting features and options, which are listed in the <a class=\"link\" href=\"https:\/\/github.com\/wareya\/nazeka\/blob\/master\/readme.md\" target=\"_blank\" rel=\"noopener\"\n>readme<\/a> of the repository. It also works in Firefox on Android.<\/p>\n<p><strong>10ten Japanese Reader<\/strong> is a port of rikaikun, which is a port of rikaichan, which is a port of rikaiXUL. It&rsquo;s very fast.<\/p>\n<p><strong>rikaichan<\/strong> is a fork of rikaiXUL, which took over the development. Originally only for Firefox, it was eventually published for Chrome too.<\/p>\n<p><strong>rikaikun<\/strong> (Chrome) started as a port of rikaichan to Chrome, when rikaichan\nwasn&rsquo;t available for Chrome yet.<\/p>\n<p><strong>RikaiRebuilt<\/strong> is a rewrite of Rikaisama for WebExtension API, which aims to keep the structure of the original extension.<\/p>\n<p><strong>Rikaisama<\/strong> is a fork of rikachan with many new features and cutomization options, but it is no longer developed and not supported by Firefox anymore.<\/p>\n<p><strong>rikaiXUL<\/strong> is an old Firefox add-on on which most of the rikai family members were\nbased.<\/p>\n<p><strong>Yomichan<\/strong> is not a fork, but rather a whole different extension which focuses\nnot only on dictionaries, but also the learning side of things. It has a built\nin integration for Anki, which makes the experience for Anki users a breeze.<\/p>\n<h3 id=\"how-can-i-decide-on-my-rikai-extension\">How can I decide on my rikai extension?<\/h3>\n<p>10ten Japanese Reader is the latest fork (deepest in the fork tree) with many performance\nimprovements and an active development community. But you should definitely\ncheck out all the other choices, explore their features and decide which one\nhas the best feel to it for you.<\/p>\n<p><em>Do you know something I don&rsquo;t? Do you want to make this more comprehensive? <a class=\"link\" href=\"https:\/\/github.com\/sorashi\/sorashi.github.io\/edit\/master\/content\/post\/comprehensive-list-of-rikai-extensions.md\" target=\"_blank\" rel=\"noopener\"\n>Edit<\/a> this page!<\/em><\/p>"}]}}