Gapful numbers: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 3,225: | Line 3,225: | ||
(Extra) The first 10 gapful numbers (>= 987,654,321) for base 12: |
(Extra) The first 10 gapful numbers (>= 987,654,321) for base 12: |
||
987654325 987654330 987654336 987654360 987654368 987654384 987654388 987654390 987654393 987654395 |
987654325 987654330 987654336 987654360 987654368 987654384 987654388 987654390 987654393 987654395 |
||
</pre> |
|||
=={{header|SQL}}== |
|||
{{works with|ORACLE 19c}} |
|||
This is not a particularly efficient solution, but it gets the job done. |
|||
<lang SQL> |
|||
/* |
|||
This code is an implementation of gapful numbers in SQL ORACLE 19c |
|||
p_start -- start point |
|||
p_count -- total number to be found |
|||
*/ |
|||
with |
|||
function gapful_numbers(p_start in integer, p_count in integer) return varchar2 is |
|||
v_start integer := p_start; |
|||
v_count integer := 0; |
|||
v_res varchar2(32767); |
|||
begin |
|||
v_res := 'First '||p_count||' gapful numbers starting from '||p_start||': '; |
|||
-- main cycle |
|||
while true loop |
|||
if mod(v_start,to_number(substr(v_start,1,1)||substr(v_start,-1))) = 0 then |
|||
v_res := v_res || v_start; |
|||
v_count := v_count + 1; |
|||
exit when v_count = p_count; |
|||
v_res := v_res || ', '; |
|||
end if; |
|||
v_start := v_start + 1; |
|||
end loop; |
|||
-- |
|||
return v_res; |
|||
-- |
|||
end; |
|||
--Test |
|||
select gapful_numbers(100,30) as res from dual |
|||
union all |
|||
select gapful_numbers(1000000,15) as res from dual |
|||
union all |
|||
select gapful_numbers(1000000000,10) as res from dual; |
|||
/ |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
First 30 gapful numbers starting from 100: 100, 105, 108, 110, 120, 121, 130, 132, 135, 140, 143, 150, 154, 160, 165, 170, 176, 180, 187, 190, 192, 195, 198, 200, 220, 225, 231, 240, 242, 253 |
|||
first 15 gapful numbers starting from 1000000: 1000000, 1000005, 1000008, 1000010, 1000016, 1000020, 1000021, 1000030, 1000032, 1000034, 1000035, 1000040, 1000050, 1000060, 1000065 |
|||
First 10 gapful numbers starting from 1000000000: 1000000000, 1000000001, 1000000005, 1000000008, 1000000010, 1000000016, 1000000020, 1000000027, 1000000030, 1000000032 |
|||
</pre> |
</pre> |
||