O'Halloran numbers: Difference between revisions

From Rosetta Code
Content added Content deleted
(Added link to the Idoneal numbers task)
Line 33: Line 33:
BEGIN # find O'Halloran numbers - numbers that cannot be the surface area of #
BEGIN # find O'Halloran numbers - numbers that cannot be the surface area of #
# a cuboid with integer dimensions #
# a cuboid with integer dimensions #
INT count := 0;
INT count := 0;
FOR n FROM 8 BY 2 TO 1000 DO
INT max area = 1 000;
INT half max area = max area OVER 2;
FOR n FROM 8 BY 2 TO max area DO
BOOL ohalloran := TRUE;
BOOL ohalloran := TRUE;
FOR l TO n WHILE ohalloran DO
FOR l TO half max area WHILE ohalloran DO
FOR b TO n WHILE INT lb = l * b;
FOR b TO half max area WHILE INT lb = l * b;
lb < n AND ohalloran
lb < n AND ohalloran
DO
DO
FOR h TO n WHILE INT bh = b * h, lh = l * h;
FOR h TO half max area WHILE INT bh = b * h, lh = l * h;
INT sum = 2 * ( lb + bh + lh );
INT sum = 2 * ( lb + bh + lh );
sum <= n
sum <= n
AND ( ohalloran := sum /= n )
AND ( ohalloran := sum /= n )
DO SKIP OD
DO SKIP OD
OD
OD

Revision as of 15:36, 2 October 2022

O'Halloran numbers is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

For this task, for our purposes, a regular integer cuboid is a 3 dimensional rectangular object, with six faces, where all angles are right angles, where opposite faces of the cuboid are equal, and where each dimension is a positive integer unit length. It will subsequently be referred to simply as a cuboid; but be aware that it references the above definition.

The surface area of a cuboid is two times the length times the width, plus two times the length times the height, plus two times the width times the height. A cuboid will always have an even integer surface area. The minimum surface area a cuboid may have is 6; one where the l, w, and h measurements are all 1.

   2 × ( l × w + w × h + h × l )
   2 × ( 1 × 1 + 1 × 1 + 1 × 1 ) = 6

Different cuboid configurations (may) yield different surface areas, but the surface area is always an integer and is always even.

A cuboid with l = 2, w = 1 h = 1 has a surface area of 10

   2 × ( 2 × 1 + 1 × 1 + 1 × 2 ) = 10

There is no configuration which will yield a surface area of 8.

There are 16 known even integer values below 1000 which can not be a surface area for any integer cuboid. It is conjectured, though not rigorously proved, that no others exist.


Task
  • Find and display the even integer values that can not be the surface area of a regular, integer, rectangular, cuboid, larger than 6 (the minimum) and less than 1000.


See also


ALGOL 68

BEGIN # find O'Halloran numbers - numbers that cannot be the surface area of  #
      #                           a cuboid with integer dimensions            #
    INT count        := 0;
    INT max area      = 1 000;
    INT half max area = max area OVER 2;
    FOR n FROM 8 BY 2 TO max area DO
        BOOL ohalloran := TRUE;
        FOR l TO half max area WHILE ohalloran DO
            FOR b TO half max area WHILE INT lb = l * b;
                                         lb < n AND ohalloran
            DO
                FOR h TO half max area WHILE INT bh = b * h, lh = l * h;
                                             INT sum = 2 * ( lb + bh + lh );
                                             sum <= n
                                             AND ( ohalloran := sum /= n )
                DO SKIP OD
            OD
        OD;
        IF ohalloran THEN
            print( ( " ", whole( n, 0 ) ) );
            count +:= 1
        FI
    OD
END
Output:
 8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924

J

   require'stats'
   2*(3}.i.501)-.+/1 */\.(|:3 comb 502)+-.i.3
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924

Here, we use combinations with repetitions to generate the various cuboid side lengths. Then we multiply all three pairs of these side length combinations and sum the pairs. Then we remove these sums from the sequence 3..500, and finally we multiply the remaining 16 values by 2.

Julia

""" Rosetta code task: rosettacode.org/wiki/O%27Halloran_numbers """

const max_area, half_max = 1000, 500
const areas = trues(max_area)

areas[1:2:max_area] .= false

for i in 1:max_area
    for j in 1:half_max
        i * j > half_max && break
        for k in 1:half_max
            area = 2 * (i * j + i * k + j * k)
            area > max_area && break
            areas[area] = false
        end
    end
end

println("Even surface areas < $max_area NOT achievable by any regular integer-valued cuboid:\n",
    [n for n in eachindex(areas) if areas[n]])
Output:
Even surface areas < 1000 NOT achievable by any regular integer-valued cuboid:
[2, 4, 8, 12, 20, 36, 44, 60, 84, 116, 140, 156, 204, 260, 380, 420, 660, 924]

Perl

use v5.36;
my @A;
my $threshold = 10_000; # redonkulous overkill

for my $x (1..$threshold) {
    X: for my $y (1..$x) {
        last X if $x*$y > $threshold;
        Y: for my $z (1..$y) {
           last Y if (my $area = 2 * ($x*$y + $y*$z + $z*$x)) > $threshold;
           $A[$area] = "$x,$y,$z";
        }
    }

say 'Even integer surface areas NOT achievable by any regular, integer dimensioned cuboid';
for (0..$#A) {
    print "$_ " if $_ < $threshold and $_ > 6 and 0 == $_ % 2 and not $A[$_];
}
Output:
Even integer surface areas NOT achievable by any regular, integer dimensioned cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924

Phix

Since we are going to check {1,1,2}, there is no point checking {1,2,1} or {2,1,1} etc.

with javascript_semantics
constant max_area = 1000, half_max = max_area/2
sequence areas = repeat(0,5)&tagset(max_area,6)

for x=1 to max_area do
    if odd(x) then areas[x] = 0 end if
    for y=x to floor(half_max/x) do
        for z=y to half_max do
            atom area = 2 * (x * y + x * z + y * z)
            if area > max_area then exit end if
            areas[area] = 0
        end for
    end for
end for

printf(1,"Even surface areas < %d NOT achievable by any regular integer-valued cuboid:\n%s\n",
         {max_area,join(filter(areas,"!=",0),fmt:="%d")})
Output:

You can also set max_area to 1,000,000 and get no more results.

Even surface areas < 1000 NOT achievable by any regular integer-valued cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924

Raku

my @Area;

my $threshold = 1000; # a little overboard to make sure we get them all

for 1..$threshold -> $x {
    for 1..$x -> $y {
        last if $x × $y > $threshold;
        for 1..$y -> $z {
           push @Area[my $area = ($x × $y + $y × $z + $z × $x) × 2], "$x,$y,$z";
           last if $area > $threshold;
        }
    }
}

say "Even integer surface areas NOT achievable by any regular, integer dimensioned cuboid:\n" ~
   @Area[^$threshold].kv.grep( { $^key > 6 and $key %% 2 and !$^value } )»[0];
Output:
Even integer surface areas NOT achievable by any regular, integer dimensioned cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924

https://rosettacode.org/wiki/O%27Halloran_numbers

Wren

import "./seq" for Lst

var found = []
for (l in 1..497) {
    for (w in 1..l) {
        var lw = l * w
        if (lw >= 498) break
        for (h in 1..w) {
            var sa = (lw + w*h + h*l) * 2
            if (sa < 1000) found.add(sa) else break
        }
    }
}
var allEven = (6..998).where { |i| i%2 == 0 }.toList
System.print("All known O'Halloran numbers:")
System.print(Lst.except(allEven,found))
Output:
All known O'Halloran numbers:
[8, 12, 20, 36, 44, 60, 84, 116, 140, 156, 204, 260, 380, 420, 660, 924]