#!/usr/bin/perl # Author: Dan Jacobson https://www.jidanni.org/ # Copyright: https://www.gnu.org/licenses/gpl.htm # Created: 2024-04-15T22:46:32+0000 # Last-Updated: 2024-06-14T19:16:11+0000 # Update #: 26 =encoding utf8 =head2 usage Given raw coordinates return the corresponding house. echo 1774.61 6492.94 | ./hnum 新社路 6500 巷 1775 號 (1775 Lane 6500 Xinshe Rd) Input: lines like 3772.31 6512.94 門牌分邊 All our blocks are mainly longer E-W than N-S. So to keep things simple, we will assume all houses lie on the E-W roads and not the N-S roads! As far as "fear of four", (tetraphobia, last digit 4) we expect by the time this program is in use, those fears will have faded. =cut use strict; use warnings q(all); my %main_road = ( zh => "新社路", en => "Xinshe Rd" ); while (<>) { chomp; my %odd; my ( $x, $y ) = split; ## (South (odd) side of) lane to the north, or (north (even) side of) lane to the south? my $lane_number = 100 * int( $y / 100 ); if ( $odd{want} = $y % 100 >= 50 ) { $lane_number += 100; } my $house_number = int $x; $odd{have} = $house_number % 2; $house_number++ if $odd{have} != $odd{want}; printf "%s %d 巷 %d 號", $main_road{zh}, $lane_number, $house_number; printf " (%d Lane %d %s)$/", $house_number, $lane_number, $main_road{en}; }