Jump to content

Numbers with same digit set in base 10 and base 16: Difference between revisions

Ada version
(Added Sidef)
(Ada version)
Line 10:
The set of digits used,   ignoring order and duplicates,   is   '''{2, 3, 9}'''   in both cases and hence this number satisfies the task requirements.
<br><br>
 
=={{header|Ada}}==
<lang Ada>with Ada.Text_Io;
 
procedure Same_Digits is
 
Columns : constant := 10;
Width : constant := 8;
 
type Set_Type is array (0 .. 15) of Boolean;
 
function Digit_Set_Of (N : Natural; Base : Natural) return Set_Type is
Nn : Natural := N;
Set : Set_Type := (others => False);
begin
while Nn /= 0 loop
Set (Nn mod Base) := True;
Nn := Nn / Base;
end loop;
return Set;
end Digit_Set_Of;
 
package Natural_Io is new Ada.Text_Io.Integer_Io (Natural);
use Ada.Text_Io, Natural_Io;
 
Count : Natural := 0;
begin
for N in 0 .. 99_999 loop
if Digit_Set_Of (N, Base => 10) = Digit_Set_Of (N, Base => 16) then
Count := Count + 1;
Put (N, Width => Width);
if Count mod Columns = 0 then
New_Line;
end if;
end if;
end loop;
New_Line;
Put ("Total numbers: "); Put (Count, Width => 3); New_Line;
end Same_Digits;</lang>
{{out}}
<pre>
0 1 2 3 4 5 6 7 8 9
53 371 913 1040 2080 2339 4100 5141 5412 5441
6182 8200 9241 13593 13665 13969 16406 20530 26946 30979
32803 33638 33840 33841 33842 33843 33844 33845 33846 33847
33848 33849 34883 37943 38931 38966 38995 66310 71444 71497
71511 75120 75121 75122 75123 75124 75125 75126 75127 75128
75129 75621 86150 88165 91465 91769 96617 98711 99481
Total numbers: 69
</pre>
 
=={{header|ALGOL W}}==
211

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.