#!/usr/bin/perl

use Math::Fraction;

$max = $ARGV[0];

if ( !$max || $max !~ /\d+/ ) { help(); }
if ( $ARGV[1] && $ARGV[1] !~ /\d+/ ) { help(); }

$cut = frac( 1, 32, MIXED );
if ( $ARGV[1] ) { $kerf = frac( $ARGV[1], 32, MIXED ); }
$kerf ||= frac( 3, 32, MIXED );
$count = 1;

$total  = $total + $cut;
$used   = $used + $cut + $kerf;
$offset = $cut + $kerf;

do {
    print "$count: Slat: $cut\", Offset: $offset\", Total: $total\", Used: $used\", Doubled: " . $total * 2 . "\"\n";

    $cut = $cut + frac( 1, 32, MIXED );

    $count++;

    $total  = $total + $cut;
    $used   = $used + $cut + $kerf;
    $offset = $cut + $kerf;

} while ( $total < $max / 2 );

sub help {

    print << "EOF";
Usage: $0 <WIDTH> [<KERF>]
Calculate cut offsets and total wood needed for a Sawmill Creek style cutting board.
See: http://www.sawmillcreek.org/showthread.php?t=2692

  WIDTH: Total width (in inches)

  KERF: (Optional) Size of kerf in 32s, default 3/32" (thin kerf)
EOF
    exit;
}
