Hi Guys,
I was involved in a coding challenge to calculate 2 pi r,
the circumference of a circle, given the radius as input, without any multiplication, division, or floats,
so I pretended I was using an 8 bit picIt was done in C, but all variables were integers,
so hopefully this BASIC is a good representation. (only the C was tested).
Cheers
Code:var word input = 300 ‘ input radius var byte twopi[19] = { 0x00,0x00,0x00,0x06,0x02,0x08,0x03,0x01,0x08,0x05,0x03,0x00,0x07,0x01,0x07,0x09,0x05,0x09,0x00 } var byte otput[19] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } var word adcnt = 0 ‘ counter var byte dgcnt = 0 ‘ digit index var byte carry = 0 ‘ carry digit while (adcnt < input) ‘ multiply through addition dgcnt = 17 : carry = 0 while (dgcnt > 0) ‘ cycle the digits otput[dgcnt] = otput[dgcnt] + twopi[dgcnt] + carry : carry = 0 ‘ add digit if (otput[dgcnt] > 9) otput[dgcnt] = otput[dgcnt] - 10 : carry = 1 endif ‘ carry digit dgcnt = dgcnt - 1 wend ‘ dgcnt if (carry != 0) otput[dgcnt] = otput[dgcnt] + 1 endif adcnt = adcnt + 1 wend ‘ adcnt twopi[18] = 0 // terminate string // answer: 1884.9555921538758 is the string in the otput array


It was done in C, but all variables were integers,


Bookmarks