#!/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-07-11T00:38:45+0000 # Update #: 36 use strict; use warnings q(all); #use English; #$OUTPUT_FIELD_SEPARATOR = ','; sub road { return 100 * sprintf( "%.0f", $_[0] / 100 ); } sub housenumber { return sprintf( "%.0f", $_[0] ); } sub distance_to_road { if ( $ENV{bad} && $ENV{bad} == 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; }