Skip to content

Instantly share code, notes, and snippets.

@Ovid
Last active December 9, 2019 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ovid/c944e00c0913a315a87394f38a35a8de to your computer and use it in GitHub Desktop.
Save Ovid/c944e00c0913a315a87394f38a35a8de to your computer and use it in GitHub Desktop.
Convert from Arabic to Babylonian numerals (only positive integers)
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
binmode STDOUT, ':utf8_strict';
my $num = shift;
if ( $num < 1 || $num != int($num) ) {
die "'$num' is not a positive integer";
}
my $base = 60;
# I'm pretty compulsive about aligning my code carefully,
# but with this font, this is as close as I can get
my %numbers = qw(
0 ␣
1 𒐕 2 𒐖 3 𒐗 4 π’˜ 5 𒐙 6 π’š 7 𒐛 8 π’œ 9 𒐝 10 π’Œ‹β£
11 π’Œ‹π’• 12 π’Œ‹π’– 13 π’Œ‹π’— 14 π’Œ‹π’˜ 15 π’Œ‹π’™ 16 π’Œ‹π’š 17 π’Œ‹π’› 18 π’Œ‹π’œ 19 π’Œ‹π’ 20 π’Ž™β£
21 π’Ž™π’• 22 π’Ž™π’– 23 π’Ž™π’— 24 π’Ž™π’˜ 25 π’Ž™π’™ 26 π’Ž™π’š 27 π’Ž™π’› 28 π’Ž™π’œ 29 π’Ž™π’ 30 π’Œβ£
31 π’Œπ’• 32 π’Œπ’– 33 π’Œπ’— 34 π’Œπ’˜ 35 π’Œπ’™ 36 π’Œπ’š 37 π’Œπ’› 38 π’Œπ’œ 39 π’Œπ’ 40 𒐏␣
41 𒐏𒐕 42 𒐏𒐖 43 𒐏𒐗 44 π’π’˜ 45 𒐏𒐙 46 π’π’š 47 𒐏𒐛 48 π’π’œ 49 𒐏𒐝 50 𒐐␣
51 𒐐𒐕 52 𒐐𒐖 53 𒐐𒐗 54 π’π’˜ 55 𒐐𒐙 56 π’π’š 57 𒐐𒐛 58 π’π’œ 59 𒐐𒐝
);
my @result;
do {
unshift @result => $num % $base;
$num = int( $num / $base );
} while ( $num >= $base );
unshift @result => $num;
my $babylonian = join ' ' => map { $numbers{$_} } @result;
print "$babylonian\n";
__END__
=encoding utf8
=head1 NAME
babylonian.pl - print Babylonian numbers
=head1 SYNOPSIS
$ ./babylonian.pl 123456789
𒐝 π’Œπ’• π’Œπ’— π’Œπ’— 𒐝
=head1 DESCRIPTION
Given a positive integer, prints the Babylonian version of it. We cheat using
a C<␣> where a zero would be with Arabic numerals, but the Babylonian's would
have used a space.
See also: https://mathandinformatic.wordpress.com/numbers-and-number-theory/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment