How to resolve the algorithm Happy numbers step by step in the Potion programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Happy numbers step by step in the Potion programming language

Table of Contents

Problem Statement

From Wikipedia, the free encyclopedia:

Find and print the first   8   happy numbers. Display an example of your output here on this page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Happy numbers step by step in the Potion programming language

Source code in the potion programming language

sqr = (n): n * n.

isHappy = (n) :
   loop :
      if (n == 1): return true.
      if (n == 4): return false.
      sum = 0
      n = n string
      n length times (i): sum = sum + sqr(n(i) number integer).
      n = sum
   .
.

firstEight = ()
i = 0
while (firstEight length < 8) :
   i++
   if (isHappy(i)): firstEight append(i).
.
firstEight string print

  

You may also check:How to resolve the algorithm Sum of squares step by step in the Trith programming language
You may also check:How to resolve the algorithm Probabilistic choice step by step in the BASIC256 programming language
You may also check:How to resolve the algorithm Death Star step by step in the Tcl programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the Picat programming language
You may also check:How to resolve the algorithm Parametric polymorphism step by step in the Inform 7 programming language