Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,8 @@
SumSqDigits := proc( n :: posint )
local s := 0;
local m := n;
while m <> 0 do
s := s + irem( m, 10, 'm' )^2
end do;
s
end proc:

View file

@ -0,0 +1,2 @@
> SumSqDigits( 1234567890987654321 );
570

View file

@ -0,0 +1,3 @@
> n := 1234567890987654321:
> `+`( op( map( parse, StringTools:-Explode( convert( n, 'string' ) ) )^~2) );
570

View file

@ -0,0 +1,13 @@
Happy? := proc( n )
if n = 1 then
true
elif n = 4 then
false
else
local s := SumSqDigits( n );
while not ( s in { 1, 4 } ) do
s := SumSqDigits( s )
end do;
evalb( s = 1 )
end if
end proc:

View file

@ -0,0 +1,3 @@
> H, S := selectremove( Happy?, [seq]( 1 .. N ) ):
> nops( H ), nops( S );
143071, 856929

View file

@ -0,0 +1,11 @@
FindHappiness := proc( N )
local count := 0;
local T := table();
for local i while count < N do
if Happy?( i ) then
count := 1 + count;
T[ count ] := i
end if
end do;
{seq}( T[ i ], i = 1 .. count )
end proc:

View file

@ -0,0 +1,2 @@
> FindHappiness( 8 );
{1, 7, 10, 13, 19, 23, 28, 31}

View file

@ -0,0 +1,9 @@
Happy? := proc( n :: posint )
local a, b;
a, b := n, SumSqDigits( n );
while a <> b do
a := SumSqDigits( a );
b := (SumSqDigits@@2)( b )
end do;
evalb( a = 1 )
end proc: