Anonymous user
Ludic numbers: Difference between revisions
m
→{{header|Eiffel}}
Line 619:
class
LUDIC_NUMBERS
create
make
feature
make (n: INTEGER)
n_positive: n > 0
i: INTEGER
create initial.make_filled (0, 1, n - 1)
create ludic_numbers.make_filled (1, 1, 1)
from
initial.put (i, i - 1)
i := i + 1
end
find_ludic_numbers
end
ludic_numbers: ARRAY [INTEGER]
feature {NONE}
initial: ARRAY [INTEGER]
find_ludic_numbers
-- Forces initial[1] into ludic_numbers before deleting it and all multiples of initial[1].
local
count: INTEGER
new_array: ARRAY [INTEGER]
create new_array.make_from_array (initial)
last := initial.count
from
count := 1
until
count > last
loop
if ludic_numbers [ludic_numbers.count] /= new_array [1] then
ludic_numbers.force (new_array [1], count + 1)
end
new_array := delete_i_elements (new_array)
count := count + 1
end
end
delete_i_elements (ar: ARRAY [INTEGER]): ARRAY [INTEGER]
ar_not_empty: ar.count > 0
length: INTEGER
do
create s_array.make_empty
i := 0
i = length
loop
if (i) \\ (ar [1]) /= 0 then
s_array.force (ar [i + 1], k)
k := k + 1
end
i := i + 1
end
if s_array.count = 0 then
Result := ar
else
Result := s_array
end
ensure
not_empty: not Result.is_empty
end
end
</lang>
Line 700 ⟶ 711:
class
APPLICATION
create
feature
make
local
k, count: INTEGER
do
create ludic.make (22000)
io.put_string ("%NLudic numbers up to 25. %N")
across
ludic.ludic_numbers.subarray (1, 25) as ld
io.put_string (ld.item.out + "%N")
end
io.put_string ("%NLudic numbers from 2000 ... 2005. %N")
ludic.ludic_numbers.subarray (2000, 2005) as ld
io.put_string (ld.item.out + "%N")
end
io.put_string ("%NNumber of Ludic numbers smaller than 1000. %N")
from
k := 1
until
ludic.ludic_numbers [k] >= 1000
loop
k := k + 1
count := count + 1
end
io.put_integer (count)
ludic: LUDIC_NUMBERS
end
</lang>
|