#!/usr/bin/perl # aih: housenumber AI. # Simplistic AI to produce addresses for houses that are assumed to have driveways # leading to the nearest rectangular road. # See also ../../taichung/xinshe/hnum # Author: Dan Jacobson https://www.jidanni.org/ # Copyright: https://www.gnu.org/licenses/gpl.htm # Created: 2026-07-09T17:48:25+0000 # Last-Updated: 2026-08-14T00:38:34+0000 # Update #: 37 use strict; use warnings q(all); sub road { return 100 * sprintf( "%.0f", $_[0] / 100 ); } sub housenumber { return sprintf( "%.0f", $_[0] ); } sub distance_to_road { ## Here we add a "back door", to make up for just using points, ## and assuming each x00 grid has a road. if ( $ENV{bad} ) { for ( $ENV{bad} ) { for (split) { if ( $_ == road $_[0] ) { return 9999999 } } } } return $_[0] - road $_[0]; } ## We make the realization that for any "single axis L", regarding the ## inner sides, which are even, one will just higher and one just ## lower... sub address { my $no = housenumber( $_[1] ); if ( ( $no % 2 ) && ( $_[2] * distance_to_road( $_[0] ) > 0 ) ) { $no++ } return road( $_[0] ), " ", $no; } while (<>) { my @F = split; if ( abs( distance_to_road $F[2] ) < abs( distance_to_road $F[3] ) ) { print address( @F[ 2, 3 ], -1 ); } else { print address( @F[ 3, 2 ], 1 ); } print " "; print; }