Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Happy-numbers/Maple/happy-numbers-1.maple
Normal file
8
Task/Happy-numbers/Maple/happy-numbers-1.maple
Normal 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:
|
||||
2
Task/Happy-numbers/Maple/happy-numbers-2.maple
Normal file
2
Task/Happy-numbers/Maple/happy-numbers-2.maple
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> SumSqDigits( 1234567890987654321 );
|
||||
570
|
||||
3
Task/Happy-numbers/Maple/happy-numbers-3.maple
Normal file
3
Task/Happy-numbers/Maple/happy-numbers-3.maple
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> n := 1234567890987654321:
|
||||
> `+`( op( map( parse, StringTools:-Explode( convert( n, 'string' ) ) )^~2) );
|
||||
570
|
||||
13
Task/Happy-numbers/Maple/happy-numbers-4.maple
Normal file
13
Task/Happy-numbers/Maple/happy-numbers-4.maple
Normal 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:
|
||||
3
Task/Happy-numbers/Maple/happy-numbers-5.maple
Normal file
3
Task/Happy-numbers/Maple/happy-numbers-5.maple
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> H, S := selectremove( Happy?, [seq]( 1 .. N ) ):
|
||||
> nops( H ), nops( S );
|
||||
143071, 856929
|
||||
11
Task/Happy-numbers/Maple/happy-numbers-6.maple
Normal file
11
Task/Happy-numbers/Maple/happy-numbers-6.maple
Normal 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:
|
||||
2
Task/Happy-numbers/Maple/happy-numbers-7.maple
Normal file
2
Task/Happy-numbers/Maple/happy-numbers-7.maple
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> FindHappiness( 8 );
|
||||
{1, 7, 10, 13, 19, 23, 28, 31}
|
||||
9
Task/Happy-numbers/Maple/happy-numbers-8.maple
Normal file
9
Task/Happy-numbers/Maple/happy-numbers-8.maple
Normal 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:
|
||||
Loading…
Add table
Add a link
Reference in a new issue