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

Answer by marinus for Implement division using only addition

$
0
0

J, 0 additions, 14 bytes

Inspired by Alexei Kopylov's answer.

f=:[{]#i.@>:@[

Uses no maths at all:

f=:                    NB. define function f             [         NB. take left argument,>:@          NB. increment it,       i.@             NB. generate the list [0..left arg+1)     ]#                NB. replicate each item in the list by the right argument                       NB. (so if ]=2, list becomes 0 0 1 1 2 2 3 3 ...)   [{                  NB. select the ['th item from that list.

Viewing all articles
Browse latest Browse all 18

Trending Articles



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