Quantcast
Channel: Implement division using only addition - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 18

Answer by Igby Largeman for Implement division using only addition

$
0
0

C# - 0 additions

using System.Collections.Generic;using System.Linq;static int Divide(int a, int b){    var ints = new List<int>(a);    while (ints.Count < a)        ints.AddRange(Enumerable.Range(1, b));    return ints.Select((x, i) => x == b && i < a).Count(x => x);}

Populates a list of integers with 1..b repeated a times. The number of times b appears (except for the occurrence with an index >a) is the result.

I'm not sure if the list is allowed by the rules, but I'm submitting this in the spirit of the other posts which aren't taking the rules all that seriously (after all, not using addition at all is basically bypassing the challenge altogether).


Viewing all articles
Browse latest Browse all 18

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>