O'Halloran numbers: Difference between revisions

Add MATLAB/Octave implementation
(→‎{{header|ALGOL 68}}: As noted by Phix, once a, b, c has been tried, there is no need to check a, c, b etc.)
(Add MATLAB/Octave implementation)
 
(34 intermediate revisions by 11 users not shown)
Line 1:
{{draft task}}
 
For this task, for our purposes, a cuboid is a 3 dimensional object, with six rectangular faces, where all angles are right angles, 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.
Line 29:
 
=={{header|ALGOL 68}}==
As noted byin the Phix sampleand other samples, wwewe only need to consider one arrangement of each l, b and h values.
<syntaxhighlight lang="algol68">
BEGIN # find O'Halloran numbers - numbers that cannot be the surface area of #
Line 42:
lb < n AND ohalloran
DO
FOR h FROM lb TO half max area WHILE INT bh = b * h, lh = l * h;
INT sum = 2 * ( lb + bh + lh );
sum <= n AND ( ohalloran := sum /= n )
Line 59:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">on OHalloranNumbers(max)
script o
property evens : {missing value, missing value}
end script
repeat with n from 6 to max by 2
set end of o's evens to n
end repeat
set halfMax to max div 2
set sixthMax to halfMax div 3
repeat with x from 1 to sixthMax
repeat with y from x to (sixthMax div x)
repeat with halfArea from ((x + x + y) * y) to halfMax by (x + y)
set o's evens's item halfArea to missing value
end repeat
end repeat
end repeat
return o's evens's integers
end OHalloranNumbers
 
OHalloranNumbers(1000 - 1)
 
(* Repeat logic condensed from:
repeat with x from 1 to sixthMax
repeat with y from x to sixthMax
set xy to x * y
if (xy > sixthMax) then exit repeat
repeat with z from y to sixthMax
set halfArea to xy + (x + y) * z
if (halfArea > halfMax) then exit repeat
set o's evens's item halfArea to missing value
end repeat
end repeat
end repeat
*)</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">{8, 12, 20, 36, 44, 60, 84, 116, 140, 156, 204, 260, 380, 420, 660, 924}</syntaxhighlight>
 
=={{header|Arturo}}==
Line 110 ⟶ 149:
<pre>All known O'Halloran numbers:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924 </pre>
 
==={{header|Chipmunk Basic}}===
{{trans|BASIC256}}
{{works with|Chipmunk Basic|3.6.4}}
{{works with|QBasic}}
<syntaxhighlight lang="vbnet">100 cls
110 maxarea = 1000
120 halfmaxarea = maxarea/2
130 dim t(halfmaxarea)'table of half areas
140 for i = 0 to halfmaxarea-1
150 t(i) = 1 'assume all are O'kalloran numbers
160 next i
170 for l = 1 to maxarea
180 for w = 1 to halfmaxarea
190 for h = 1 to halfmaxarea
200 suma = l*w+l*h+w*h
210 if suma < halfmaxarea then t(suma) = 0 'not an O'kalloran number
220 next h
230 next w
240 next l
250 print "All known O'Halloran numbers:"
260 print "[ ";
270 for l = 6/2 to halfmaxarea-1
280 if t(l) then print int(l*2);" ";
290 next l
300 print chr$(8);"]"
310 end</syntaxhighlight>
 
==={{header|FreeBASIC}}===
Line 137 ⟶ 203:
<pre>All known O'Halloran numbers:
[ 8, 12, 20, 36, 44, 60, 84, 116, 140, 156, 204, 260, 380, 420, 660, 924 ]</pre>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
The [[#Chipmunk Basic|Chipmunk Basic]] solution works without any changes.
 
==={{header|True BASIC}}===
{{trans|BASIC256}}
<syntaxhighlight lang="qbasic">LET maxarea = 1000
LET halfmaxarea = maxarea/2
DIM t(1)
MAT REDIM t(0 TO halfmaxarea) !Table of half areas
FOR i = 0 TO halfmaxarea-1
LET t(i) = 1 !assume all are O'kalloran numbers
NEXT i
FOR l = 1 TO maxarea
FOR w = 1 TO halfmaxarea
FOR h = 1 TO halfmaxarea
LET suma = l*w+l*h+w*h
IF suma < halfmaxarea THEN LET t(suma) = 0 !not an O'kalloran number
NEXT h
NEXT w
NEXT l
PRINT "All known O'Halloran numbers:"
FOR l = 6/2 TO halfmaxarea-1
IF t(l) = 1 THEN PRINT INT(l*2);" ";
NEXT l
END</syntaxhighlight>
 
==={{header|Yabasic}}===
Line 199 ⟶ 293:
[8, 12, 20, 36, 44, 60, 84, 116, 140, 156, 204, 260, 380, 420, 660, 924]
</pre>
 
 
=={{header|C#}}==
<syntaxhighlight lang="C#">
using System;
using System.Linq;
 
class OHalloranNumbers
{
static void Main(string[] args)
{
int maximumArea = 1000;
int halfMaximumArea = maximumArea / 2;
 
bool[] ohalloranNumbers = Enumerable.Repeat(true, halfMaximumArea).ToArray();
 
for (int length = 1; length < maximumArea; length++)
{
for (int width = 1; width < halfMaximumArea; width++)
{
for (int height = 1; height < halfMaximumArea; height++)
{
int halfArea = length * width + length * height + width * height;
if (halfArea < halfMaximumArea)
{
ohalloranNumbers[halfArea] = false;
}
}
}
}
 
Console.WriteLine("Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:");
for (int i = 3; i < halfMaximumArea; i++)
{
if (ohalloranNumbers[i])
{
Console.Write(i * 2 + " ");
}
}
Console.WriteLine();
}
}
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <cstdint>
#include <iostream>
#include <vector>
 
int main() {
const uint32_t maximum_area = 1'000;
const uint32_t half_maximum_area = maximum_area / 2;
 
std::vector<uint32_t> ohalloran_numbers(half_maximum_area, true);
 
for ( uint32_t length = 1; length < maximum_area; ++length ) {
for ( uint32_t width = 1; width < half_maximum_area; ++width ) {
for ( uint32_t height = 1; height < half_maximum_area; ++height ) {
uint32_t half_area = length * width + length * height + width * height;
if ( half_area < half_maximum_area ) {
ohalloran_numbers[half_area] = false;
}
}
}
}
 
std::cout << "Values larger than 6 and less than 1_000 which cannot be the surface area of a cuboid:"
<< std::endl;
for ( uint32_t i = 3; i < half_maximum_area; ++i ) {
if ( ohalloran_numbers[i] ) {
std::cout << i * 2 << " ";
}
}
std::cout << std::endl;
}
</syntaxhighlight>
{{ out }}
<pre>
Values larger than 6 and less than 1_000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
=={{header|Dart}}==
{{trans|Scala}}
<syntaxhighlight lang="Dart">
import "dart:io";
 
void main() {
const int maximumArea = 1000;
int halfMaximumArea = maximumArea ~/ 2;
 
List<bool> ohalloranNumbers = List<bool>.filled(halfMaximumArea, true);
 
for (int length = 1; length < maximumArea; length++) {
for (int width = 1; width < halfMaximumArea; width++) {
for (int height = 1; height < halfMaximumArea; height++) {
int halfArea = length * width + length * height + width * height;
if (halfArea < halfMaximumArea) {
ohalloranNumbers[halfArea] = false;
}
}
}
}
 
print("Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:");
for (int i = 3; i < halfMaximumArea; i++) {
if (ohalloranNumbers[i]) {
stdout.write('${i * 2} ');
}
}
}
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
procedure ShowOHalloranNumbers(Memo: TMemo);
var L, W, H: integer;
var CubeArea, I, Cnt: integer;
const Limit = 1000;
const Limit2 = Limit div 2;
const Limit4 = Limit div 4;
var ValidOH: array [0..Limit2] of boolean;
var S: string;
begin
{Since we are using CuboidArea/2, use half the space }
for I:= 0 to Limit2-1 do ValidOH[I]:= true;
for L:= 1 to Limit4 do
for W:= 1 to L do
for H:= 1 to L do
begin
{Calculate 1/2 Cuboid value}
CubeArea:=L * W + L * H + W * H;
{Make sure number doesn't overrun array}
if CubeArea>=Length(ValidOH) then continue;
{Mark it as not an OHalloran number}
ValidOH[CubeArea]:= false;
end;
S:=''; Cnt:=0;
{Since we are using half the space}
{everything has to be doubled}
for I:=2 * 3 to Limit2-1 do
if ValidOH[I] then
begin
Inc(Cnt);
S:=S+Format('%8D',[I*2]);
If (Cnt mod 5)=0 then S:=S+CRLF;
end;
 
Memo.Lines.Add(S);
Memo.Lines.Add('Count='+IntToStr(Cnt));
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
12 20 36 44 60
84 116 140 156 204
260 380 420 660 924
 
Count=15
Elapsed Time: 6.353 ms.
 
</pre>
 
 
=={{header|EasyLang}}==
{{trans|C}}
<syntaxhighlight>
len found[] 1000
for l = 1 to 497
for w = 1 to l
lw = l * w
if lw >= 498
break 1
.
for h = 1 to w
sa = (lw + w * h + h * l) * 2
if sa <= 1000
found[sa] = 1
.
.
.
.
for i = 6 step 2 to 998
if found[i] = 0
write i & " "
.
.
</syntaxhighlight>
 
=={{header|Fortran}}==
{{trans|Julia}}
<syntaxhighlight lang="Fortran">
program ohalloran_numbers
implicit none
integer, parameter :: max_area = 1000
integer :: half_max, i, j, k, area
logical, dimension(max_area) :: areas
half_max = max_area / 2
! Initialize areas with .TRUE.
areas = .TRUE.
do i = 1, max_area
do j = 1, half_max
if (i * j > half_max) exit
do k = 1, half_max
area = 2 * (i * j + i * k + j * k)
if (area > max_area) exit
areas(area) = .FALSE. ! Mark as not an O'Halloran number
end do
end do
end do
! Print the O'Halloran numbers
print *, "Even surface areas < NOT ", max_area, " achievable by any regular integer-valued cuboid:"
do i = 1, max_area
if (mod(i, 2) == 0 .AND. areas(i)) then
write(*,'(I4,1X)', advance='no') i
endif
end do
print *, "" ! To add a final newline after the list
end program ohalloran_numbers
</syntaxhighlight>
{{out}}
<pre>
Even surface areas < NOT 1000 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
</pre>
 
 
 
=={{header|FutureBasic}}==
Line 279 ⟶ 621:
 
Here, we use [[Combinations_with_repetitions#J|combinations with repetitions]] to generate the various relevant 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.
 
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.util.Arrays;
 
public final class OHalloranNumbers {
 
public static void main(String[] args) {
final int maximumArea = 1_000;
final int halfMaximumArea = maximumArea / 2;
boolean[] ohalloranNumbers = new boolean[halfMaximumArea];
Arrays.fill(ohalloranNumbers, true);
for ( int length = 1; length < maximumArea; length++ ) {
for ( int width = 1; width < halfMaximumArea; width++ ) {
for ( int height = 1; height < halfMaximumArea; height++ ) {
int halfArea = length * width + length * height + width * height;
if ( halfArea < halfMaximumArea ) {
ohalloranNumbers[halfArea] = false;
}
}
}
}
System.out.println("Values larger than 6 and less tha 1_000 which cannot be the surface area of a cuboid:");
for ( int i = 3; i < halfMaximumArea; i++ ) {
if ( ohalloranNumbers[i] ) {
System.out.print(i * 2 + " ");
}
}
System.out.println();
}
 
}
</syntaxhighlight>
{{ out }}
<pre>
Values larger than 6 and less than 1_000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
=={{header|JavaScript}}==
{{Trans|ALGOL 68}}
<syntaxhighlight lang="javascript">
// find O'Halloran numbers - numbers that cannot be the surface area of
// a cuboid with integer dimensions
'use strict'
const maxArea = 1000
const halfMaxArea = Math.trunc( maxArea / 2 )
let list = ""
for( let n = 8; n <= maxArea; n += 2 )
{
let oHalloran = true
for( let l = 1; l <= halfMaxArea && oHalloran; l ++ )
{
for( let b = l; b <= halfMaxArea; b ++ )
{
const lb = l * b
if( lb >= n || ! oHalloran )break
for( let h = b; h <= halfMaxArea; h ++ )
{
const bh = b * h, lh = l * h
const sum = 2 * ( lb + bh + lh )
oHalloran = sum != n
if( sum > n || ! oHalloran )break;
}
}
}
if( oHalloran )
{
list = list + " " + n
}
}
console.log( list )
</syntaxhighlight>
{{out}}
<pre>
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
=={{header|jq}}==
Line 339 ⟶ 761:
[2, 4, 8, 12, 20, 36, 44, 60, 84, 116, 140, 156, 204, 260, 380, 420, 660, 924]
</pre>
 
=={{header|Kotlin}}==
{{trans|Scala}}
<syntaxhighlight lang="Kotlin">
object OHalloranNumbers {
 
@JvmStatic
fun main(args: Array<String>) {
val maximumArea = 1_000
val halfMaximumArea = maximumArea / 2
 
var ohalloranNumbers = BooleanArray(halfMaximumArea) { true }
 
for (length in 1 until maximumArea) {
for (width in 1 until halfMaximumArea) {
for (height in 1 until halfMaximumArea) {
val halfArea = length * width + length * height + width * height
if (halfArea < halfMaximumArea) {
ohalloranNumbers[halfArea] = false
}
}
}
}
 
println("Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:")
for (i in 3 until halfMaximumArea) {
if (ohalloranNumbers[i]) {
print("${i * 2} ")
}
}
println()
}
}
 
fun main() {
OHalloranNumbers.main(arrayOf())
}
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
 
 
=={{header|Lua}}==
<syntaxhighlight lang="Lua">
function calculateOHalloranNumbers(maximumArea)
local halfMaximumArea = maximumArea / 2
local ohalloranNumbers = {}
 
-- Initialize the ohalloranNumbers table with all true values
for i = 1, halfMaximumArea do
ohalloranNumbers[i] = true
end
 
-- Calculate surface areas of possible cuboids and exclude them
for length = 1, maximumArea - 1 do
for width = 1, halfMaximumArea - 1 do
for height = width, halfMaximumArea - 1 do
local halfArea = length * width + length * height + width * height
if halfArea < halfMaximumArea then
ohalloranNumbers[halfArea] = false
else
break
end
end
if length * width * 2 >= halfMaximumArea then
break
end
end
end
 
-- Print out the O'Halloran numbers
print("Values larger than 6 and less than " .. maximumArea .. " which cannot be the surface area of a cuboid:")
for i = 3, halfMaximumArea-1 do
if ohalloranNumbers[i] then
io.write((2 * (i)) .. " ")
end
end
print()
end
 
-- Call the function with the maximum area of 1000
calculateOHalloranNumbers(1000)
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="Mathematica">
(* Rosetta code task: rosettacode.org/wiki/O%27Halloran_numbers *)
 
maxArea = 1000;
halfMax = 500;
areas = Table[True, {maxArea}];
 
areas[[1 ;; maxArea ;; 2]] = False;
 
For[i = 1, i <= maxArea, i++,
For[j = 1, j <= halfMax,
j++, If[i*j > halfMax, Break[]];
For[k = 1, k <= halfMax,
k++, area = 2 (i*j + i*k + j*k);
If[area > maxArea, Break[]];
areas[[area]] = False;
];
];
];
 
Print["Even surface areas < ", maxArea, " NOT achievable by any regular integer-valued cuboid:\n",
Select[Range[maxArea], areas[[#]] &]]
</syntaxhighlight>
{{out}}
<pre>
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}
</pre>
 
=={{header|MATLAB}}/{{header|Octave}}==
{{trans|Julia}}
<syntaxhighlight lang="MATLAB">
max_area = 1000;
half_max = max_area / 2;
areas = ones(1, max_area); % Initialize areas with 1's
 
for i = 1:max_area
for j = 1:half_max
if (i * j > half_max)
break;
endif
for k = 1:half_max
area = 2 * (i * j + i * k + j * k);
if (area > max_area)
break;
endif
areas(area) = 0; % Mark as not an O'Halloran number
endfor
endfor
endfor
 
% Print the O'Halloran numbers
printf("Even surface areas < NOT %d achievable by any regular integer-valued cuboid:\n", max_area);
for n = 1:max_area/2
if (areas(2*n))
printf("%d ", 2*n);
endif
endfor
printf("\n");
</syntaxhighlight>
{{out}}
<pre>
Even surface areas < NOT 1000 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
 
</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="Nim">import std/algorithm
 
const
M = 1000 # Maximum area.
N = M div 2 # Maximum half area.
 
var isOHalloran: array[3..N, bool]
isOHalloran.fill(true)
 
for length in 1..N:
for width in 1..length:
let plw = length * width
if plw > N: break
let slw = length + width
for height in 1..width:
let halfArea = plw + height * slw
if halfArea > N: break
isOHalloran[halfArea] = false
 
echo "All known O'Halloran numbers:"
for n in 3..N:
if isOHalloran[n]:
stdout.write 2 * n, ' '
echo()
</syntaxhighlight>
 
{{out}}
<pre>All known O'Halloran numbers:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="OCaml">
let maximum_area = 1000;;
let half_maximum_area = maximum_area / 2;;
 
let ohalloran_numbers = Array.make half_maximum_area true;;
 
for length = 1 to maximum_area - 1 do
for width = 1 to half_maximum_area - 1 do
for height = 1 to half_maximum_area - 1 do
let half_area = length * width + length * height + width * height in
if half_area < half_maximum_area then
ohalloran_numbers.(half_area) <- false
done;
done;
done;;
 
Printf.printf "Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:\n";
for i = 3 to half_maximum_area - 1 do
if ohalloran_numbers.(i) then
Printf.printf "%d " (i * 2)
done;
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
=={{header|PARI/GP}}==
{{trans|Julia}}
<syntaxhighlight lang="PARI/GP">
{
max_area = 1000;
half_max = max_area / 2;
areas = vector(max_area, i, 1); /* Initialize areas with 1's */
 
for (i = 1, max_area,
for (j = 1, half_max,
if (i * j > half_max, break);
for (k = 1, half_max,
area = 2 * (i * j + i * k + j * k);
if (area > max_area, break);
areas[area] = 0; /* Mark as not an O'Halloran number */
)
)
);
 
/* Print the O'Halloran numbers */
print("Even surface areas < NOT ", Str(max_area) , " achievable by any regular integer-valued cuboid:");
for (n = 2/2, max_area/2,
if (areas[2*n], print1(2*n, " "));
);
}
</syntaxhighlight>
{{out}}
<pre>
Even surface areas < NOT 1000 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
</pre>
 
 
 
 
=={{header|Perl}}==
Line 388 ⟶ 1,067:
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
</pre>
 
=={{header|PHP}}==
{{trans|Scala}}
<syntaxhighlight lang="PHP">
<?php
 
function main() {
$maximumArea = 1000;
$halfMaximumArea = $maximumArea / 2;
 
$ohalloranNumbers = array_fill(0, $halfMaximumArea, true);
 
for ($length = 1; $length < $maximumArea; $length++) {
for ($width = 1; $width < $halfMaximumArea; $width++) {
for ($height = 1; $height < $halfMaximumArea; $height++) {
$halfArea = $length * $width + $length * $height + $width * $height;
if ($halfArea < $halfMaximumArea) {
$ohalloranNumbers[$halfArea] = false;
}
}
}
}
 
echo "Values larger than 6 and less than $maximumArea which cannot be the surface area of a cuboid:\n";
for ($i = 3; $i < $halfMaximumArea; $i++) {
if ($ohalloranNumbers[$i]) {
echo ($i * 2) . " ";
}
}
echo "\n";
}
 
main();
 
?>
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
Line 442 ⟶ 1,163:
l = 1
REPEAT
b = 1l
lb = l * b
REPEAT
h = 1b
REPEAT
bh = b * h
Line 469 ⟶ 1,190:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
=={{header|R}}==
{{trans|Julia}}
<syntaxhighlight lang="R">
max_area <- 1000
half_max <- max_area / 2
areas <- rep(1, max_area) # Initialize areas with 1's
 
for (i in 1:max_area) {
for (j in 1:half_max) {
if (i * j > half_max) {
break
}
for (k in 1:half_max) {
area <- 2 * (i * j + i * k + j * k)
if (area > max_area) {
break
}
areas[area] <- 0 # Mark as not an O'Halloran number
}
}
}
 
# Print the O'Halloran numbers
cat("Even surface areas < NOT", max_area, "achievable by any regular integer-valued cuboid:\n")
for (n in 3:(max_area/2)) {
if (areas[2*n] == 1) {
cat(2*n, " ")
}
}
cat("\n") # To ensure the output ends with a newline
</syntaxhighlight>
{{out}}
<pre>
Even surface areas < NOT 1000 achievable by any regular integer-valued cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
 
=={{header|Racket}}==
{{trans|Scala}}
<syntaxhighlight lang="Racket">
#lang racket
 
(define (main)
(let ([maximum-area 1000]
[ohalloran-numbers (make-hash)])
;; Initialize the hash table
(for ([i (in-range (quotient maximum-area 2))])
(hash-set! ohalloran-numbers i #t))
 
;; Calculate cuboid surface areas and update the hash table
(for* ([length (in-range 1 maximum-area)]
[width (in-range 1 (quotient maximum-area 2))]
[height (in-range 1 (quotient maximum-area 2))])
(let* ([half-area (+ (* length width) (* length height) (* width height))])
(when (< half-area (quotient maximum-area 2))
(hash-set! ohalloran-numbers half-area #f))))
 
;; Print the results
(printf "Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:\n")
(for ([i (in-range 3 (quotient maximum-area 2))])
(when (hash-ref ohalloran-numbers i)
(printf "~a " (* i 2))))
(printf "\n")))
 
(main)
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
 
 
=={{header|Raku}}==
Line 490 ⟶ 1,286:
<pre>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</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="Ruby">
class OHalloranNumbers
def self.main
maximum_area = 1_000
half_maximum_area = maximum_area / 2
 
ohalloran_numbers = Array.new(half_maximum_area, true)
 
(1...maximum_area).each do |length|
(1...half_maximum_area).each do |width|
(1...half_maximum_area).each do |height|
half_area = length * width + length * height + width * height
ohalloran_numbers[half_area] = false if half_area < half_maximum_area
end
end
end
 
puts "Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:"
(3...half_maximum_area).each do |i|
print "#{i * 2} " if ohalloran_numbers[i]
end
puts
end
end
 
OHalloranNumbers.main
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
 
 
=={{header|Rust}}==
{{trans|C++}}
<syntaxhighlight lang="Rust">
fn main() {
const MAXIMUM_AREA: u32 = 1_000;
const HALF_MAXIMUM_AREA: u32 = MAXIMUM_AREA / 2;
 
let mut ohalloran_numbers = vec![true; HALF_MAXIMUM_AREA as usize];
 
for length in 1..MAXIMUM_AREA {
for width in 1..HALF_MAXIMUM_AREA {
for height in 1..HALF_MAXIMUM_AREA {
let half_area = length * width + length * height + width * height;
if half_area < HALF_MAXIMUM_AREA {
ohalloran_numbers[half_area as usize] = false;
}
}
}
}
 
println!("Values larger than 6 and less than 1_000 which cannot be the surface area of a cuboid:");
for i in 3..HALF_MAXIMUM_AREA {
if ohalloran_numbers[i as usize] {
print!("{} ", i * 2);
}
}
println!();
}
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1_000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
 
 
=={{header|RPL}}==
{{trans|JavaScript}}
{{works with|HP|48}}
 
« 1000 DUP 2 / FLOOR 1 → maxarea halfmax ohalloran
« { }
8 maxarea '''FOR''' n
1 ohalloran SF
'''WHILE''' DUP halfmax ≤ ohalloran FS? AND '''REPEAT'''
1 halfmax '''FOR''' b
DUP b *
'''IF''' DUP n ≥ ohalloran FC? OR '''THEN''' DROP halfmax 'b' STO
'''ELSE'''
b halfmax '''FOR''' h
OVER h * OVER + h b * + DUP +
'''IF''' DUP n == '''THEN''' ohalloran CF '''END'''
'''IF''' n > ohalloran FC? OR '''THEN''' halfmax 'h' STO '''END'''
'''NEXT''' DROP
'''END'''
'''NEXT'''
1 +
'''END''' DROP
'''IF''' ohalloran FS? '''THEN''' n + '''END'''
2 '''STEP'''
» » '<span style="color:blue">OHALL</span>' STO
{{out}}
<pre>
1: { 8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924 }
</pre>
 
=={{header|Scala}}==
{{trans|Java}}
<syntaxhighlight lang="Scala">
object OHalloranNumbers {
 
def main(args: Array[String]): Unit = {
val maximumArea = 1_000
val halfMaximumArea = maximumArea / 2
 
var ohalloranNumbers = Array.fill[Boolean](halfMaximumArea)(true)
 
for {
length <- 1 until maximumArea
width <- 1 until halfMaximumArea
height <- 1 until halfMaximumArea
} {
val halfArea = length * width + length * height + width * height
if (halfArea < halfMaximumArea) {
ohalloranNumbers(halfArea) = false
}
}
 
println("Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:")
for {
i <- 3 until halfMaximumArea
if ohalloranNumbers(i)
} {
print(i * 2 + " ")
}
println()
}
}
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
=={{header|Swift}}==
{{trans|Scala}}
<syntaxhighlight lang="Swift">
import Foundation
 
func main() {
let maximumArea = 1_000
let halfMaximumArea = maximumArea / 2
 
var ohalloranNumbers = Array(repeating: true, count: halfMaximumArea)
 
for length in 1..<maximumArea {
for width in 1..<halfMaximumArea {
for height in 1..<halfMaximumArea {
let halfArea = length * width + length * height + width * height
if halfArea < halfMaximumArea {
ohalloranNumbers[halfArea] = false
}
}
}
}
 
print("Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:")
for i in 3..<halfMaximumArea where ohalloranNumbers[i] {
print(i * 2, terminator: " ")
}
print()
}
 
// Running the main function
main()
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
=={{header|Tcl}}==
<syntaxhighlight lang="Tcl">
proc calculateOHalloranNumbers { maximumArea } {
set halfMaximumArea [expr {$maximumArea / 2}]
set ohalloranNumbers [list]
# Initialize the ohalloranNumbers list with all true values
for {set i 0} {$i < $halfMaximumArea} {incr i} {
lappend ohalloranNumbers true
}
 
# Calculate surface areas of possible cuboids and exclude them
for {set length 1} {$length < $maximumArea} {incr length} {
for {set width 1} {$width < $halfMaximumArea} {incr width} {
for {set height $width} {$height < $halfMaximumArea} {incr height} {
set halfArea [expr {$length * $width + $length * $height + $width * $height}]
if {$halfArea < $halfMaximumArea} {
lset ohalloranNumbers $halfArea false
} else {
break
}
}
if { $length * $width * 2 >= $halfMaximumArea } {
break
}
}
}
 
# Print out the O'Halloran numbers
puts "Values larger than 6 and less than $maximumArea which cannot be the surface area of a cuboid:"
for {set i 3} {$i < $halfMaximumArea} {incr i} {
if {[lindex $ohalloranNumbers $i]} {
puts -nonewline "[expr {2 * $i}] "
}
}
puts ""
}
 
# Call the procedure with the maximum area of 1000
calculateOHalloranNumbers 1000
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "./seq" for Lst
 
var found = []
Line 507 ⟶ 1,531:
var allEven = (6..998).where { |i| i%2 == 0 }.toList
System.print("All known O'Halloran numbers:")
System.print(Lst.except(allEven, found))</syntaxhighlight>
 
{{out}}
338

edits