# One Solution

### From Hamsterworks Wiki!

Here is one solution to the problem posed in The HDL paradigm in a Spreadsheet

A | B | C | D | |
---|---|---|---|---|

1 | 100 | 0 | 0 | 0 |

2 | 133 | =B1+A1 | =C1+1 | =if(c1>0,B1/C1,0) |

3 | 80 | =B2+A2 | =C2+1 | =if(c2>0,B2/C2,0) |

4 | 15 | =B3+A3 | =C3+1 | =if(c3>0,B3/C3,0) |

5 | 20 | =B4+A4 | =C4+1 | =if(c4>0,B4/C4,0) |

6 | 200 | =B5+A5 | =C5+1 | =if(c5>0,B5/C5,0) |

7 | =B6+A6 | =C6+1 | =if(c6>0,B6/C6,0) | |

8 | =B7+A7 | =C7+1 | =if(c7>0,B7/C7,0) |

The average of the numbers will be in cell D8.

So there you have it - computing the average of a list of numbers without loops, and with all assignments happening every step of the clock

And so you can see what this looks like in HDL here is the equivalent expressed in VHDL

process(clk) begin if rising_edge(clk) then if count /= 0 then average <= total / count; else average <= 0; end if; count <= count+1; total <= total+value; end if; end process;