How to resolve the algorithm Ludic numbers step by step in the Elixir programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ludic numbers step by step in the Elixir programming language
Table of Contents
Problem Statement
Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers. The first ludic number is 1. To generate succeeding ludic numbers create an array of increasing integers starting from 2. (Loop)
Show all triplets of ludic numbers < 250.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Ludic numbers step by step in the Elixir programming language
Source code in the elixir programming language
defmodule Ludic do
def numbers(n \\ 100000) do
[h|t] = Enum.to_list(1..n)
numbers(t, [h])
end
defp numbers(list, nums) when length(list) < hd(list), do: Enum.reverse(nums, list)
defp numbers([h|_]=list, nums) do
Enum.drop_every(list, h) |> numbers([h | nums])
end
def task do
IO.puts "First 25 : #{inspect numbers(200) |> Enum.take(25)}"
IO.puts "Below 1000: #{length(numbers(1000))}"
tuple = numbers(25000) |> List.to_tuple
IO.puts "2000..2005th: #{ inspect for i <- 1999..2004, do: elem(tuple, i) }"
ludic = numbers(250)
triple = for x <- ludic, x+2 in ludic, x+6 in ludic, do: [x, x+2, x+6]
IO.puts "Triples below 250: #{inspect triple, char_lists: :as_lists}"
end
end
Ludic.task
You may also check:How to resolve the algorithm Combinations and permutations step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Generic swap step by step in the Gecho programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Swift programming language
You may also check:How to resolve the algorithm Array length step by step in the XLISP programming language
You may also check:How to resolve the algorithm Runtime evaluation step by step in the Ring programming language