#!/usr/bin/perl -w # Strict use strict; use warnings; use Data::Dumper; # User defined my $text = " It's been said ever so often by many an expert that in ol' plain text one neer can get a round tuit, but just look here "; # Main program $text =~ s/(? text = [$text]\n"; # Show text $text =~ s/\s+//; # Strip all other spaces $text =~ s/\n/@/gs; # Convert newlines to '@' my @text = grep { /\S/ms } split //, $text; # Split text into characters # Find the mass of the diamond my $mass = (my $temp = $text) =~ s/\S/./g; print "Debug2> mass = [$mass]\n"; # Circle mass 'm' = pi * r^2, so the radius 'r' = sqrt(m / pi) my $radius = sqrt($mass / 3.14159265358); print "Debug3> radius = $radius\n"; # Format the text into a circle, my $circle = ""; my $aspect = 1.0; for (my $row = -($radius + 10); $row <= ($radius + 10); $row++) { for (my $col = -($radius + 10); $col <= ($radius + 10); $col++) { my $char = " "; if (($aspect * $row) ** 2 + $col ** 2 <= $aspect * ($radius ** 2)) { $char = shift @text || '*'; } $circle .= ($char eq '@'? ' ': $char); } $circle .= "\n"; } # Show the resulting circle print "$circle\n"; __END__ Output: Debug1> text = [ It's been@said ever@so@often by@many@an@expert that@in@ol'@plain@text one@neer@can@get@a round@tuit,@but just@look here ] Debug2> mass = [120] Debug3> radius = 6.18038723238067 It's be en said e ver so ofte n by many a n expert tha t in ol' pla in text one neer can get a round tu it, but ju st look here