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

Published on 12 May 2024 09:40 PM
#J

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

Table of Contents

Problem Statement

An   eban   number is a number that has no letter   e   in it when the number is spelled in English. Or more literally,   spelled numbers that contain the letter   e   are banned.

The American version of spelling numbers will be used here   (as opposed to the British). 2,000,000,000   is two billion,   not   two milliard.

Only numbers less than   one sextillion   (1021)   will be considered in/for this task. This will allow optimizations to be used.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Eban numbers step by step in the J programming language

Source code in the j programming language

Filter =: (#~`)(`:6)

itemAmend =: (29&< *. <&67)`(,: 10&|)}
iseban =: [: *./ 0 2 4 6 e.~ [: itemAmend [: |: (4#1000)&#:


   (;~ #) iseban Filter >: i. 1000
┌──┬─────────────────────────────────────────────────────┐
192 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66
└──┴─────────────────────────────────────────────────────┘

   NB. INPUT are the correct integers, head and tail shown
   ({. , {:) INPUT =: 1000 + i. 3001
1000 4000
   
   (;~ #)  iseban Filter INPUT
┌──┬────────────────────────────────────────────────────────────────────────────────────────────────────────┐
212000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000
└──┴────────────────────────────────────────────────────────────────────────────────────────────────────────┘
   (, ([: +/ [: iseban [: >: i.))&> 10000 * 10 ^ i. +:2
 10000   79
100000  399
   1e6  399
   1e7 1599


ebanseq=: {{ (#~ y>:])}.,@([+/~1000*])^:(6<.<.1000^.y)~(,0 2 4 6+/~10*0 3 4 5 6) }}

   (,:&":~ #) ebanseq 1000
19                                                   
2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66
   (,:&":~ #) (#~ 1000<])ebanseq 4000
21                                                                                                      
2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000
   # ebanseq 1e4
79
   # ebanseq 1e5
399
   # ebanseq 1e6
399
   # ebanseq 1e7
1599
   # ebanseq 1e8
7999
   # ebanseq 1e9
7999
   # ebanseq 1e10
31999
   # ebanseq 1e11
159999
   # ebanseq 1e12
159999
   # ebanseq 1e13
639999
   # ebanseq 1e14
3199999
   # ebanseq 1e15
3199999
   # ebanseq 1e16
12799999
   # ebanseq 1e17
63999999


  

You may also check:How to resolve the algorithm String case step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the Aime programming language
You may also check:How to resolve the algorithm Identity matrix step by step in the Vala programming language
You may also check:How to resolve the algorithm Mertens function step by step in the Haskell programming language
You may also check:How to resolve the algorithm Sequence: nth number with exactly n divisors step by step in the C++ programming language