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

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Happy numbers step by step in the J 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 J programming language

Source code in the j programming language

   8{. (#~1=+/@(*:@(,.&.":))^:(1&~:*.4&~:)^:_ "0) 1+i.100
1 7 10 13 19 23 28 31


 f ^: cond ^: _   input


 (binary array) # 1..100


   cond=: 1&~: *. 4&~:     NB. not equal to 1 and not equal to 4
   sumSqrDigits=: +/@(*:@(,.&.":))

   sumSqrDigits 123        NB. test sum of squared digits
14
   8{. (#~ 1 = sumSqrDigits ^: cond ^:_ "0) 1 + i.100
1 7 10 13 19 23 28 31


  

You may also check:How to resolve the algorithm Idiomatically determine all the lowercase and uppercase letters step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Range expansion step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Set puzzle step by step in the Rust programming language
You may also check:How to resolve the algorithm Multi-dimensional array step by step in the Factor programming language
You may also check:How to resolve the algorithm Integer overflow step by step in the AutoHotkey programming language