How to resolve the algorithm Egyptian division step by step in the J programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Egyptian division step by step in the J programming language
Table of Contents
Problem Statement
Egyptian division is a method of dividing integers using addition and doubling that is similar to the algorithm of Ethiopian multiplication Algorithm: Given two numbers where the dividend is to be divided by the divisor:
Example: 580 / 34 Table creation: Initialization of sums: Considering table rows, bottom-up: When a row is considered it is shown crossed out if it is not accumulated, or bold if the row causes summations. So 580 divided by 34 using the Egyptian method is 17 remainder (578 - 580) or 2.
The task is to create a function that does Egyptian division. The function should closely follow the description above in using a list/array of powers of two, and another of doublings.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Egyptian division step by step in the J programming language
Source code in the j programming language
doublings=:_1 }. (+:@]^:(> {:)^:a: (,~ 1:))
ansacc=: 1 }. (] + [ * {.@[ >: {:@:+)/@([,.doublings)
egydiv=: (0,[)+1 _1*ansacc
580 doublings 34
1 34
2 68
4 136
8 272
16 544
580 ansacc 34
17 578
580 egydiv 34
17 2
You may also check:How to resolve the algorithm Knapsack problem/Bounded step by step in the Java programming language
You may also check:How to resolve the algorithm Variadic function step by step in the Qi programming language
You may also check:How to resolve the algorithm Man or boy test step by step in the Zig programming language
You may also check:How to resolve the algorithm Multifactorial step by step in the Aime programming language
You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the PostScript programming language