# ActionScript challenge (im struggling)

**URL:** <https://forum.kirupa.com/t/actionscript-challenge-im-struggling/280678>\
**Category:** flash\
**Created:** [January 30, 2009, 10:09am UTC](https://forum.kirupa.com/t/actionscript-challenge-im-struggling/280678 "2009-01-30T10:09:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![simononestop](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@simononestop](https://forum.kirupa.com/u/simononestop)\
**Post date:** [January 30, 2009, 10:09am UTC](https://forum.kirupa.com/t/actionscript-challenge-im-struggling/280678/1 "2009-01-30T10:09:11Z")

</div>

I am struggling to write a piece of script which is part of my fencing estmator.  
If any one can help me I would be well chuffed!!

We sell fencing in 3m, 2.4m and 1.8m panels.  
I need to write a function which finds the best (least panels) combination of sections for the length of fence.

eg 40m = 13no 3m sections and 1no 1.8m section (total 40.8m but the closest you can get in sold panels).

I can work out what the total length would be in 3m’s and in 2.4m’s and in 1.8m’s but I can figure out how to write the code to decide the best & closest combination?

some thing like this (this is straight out my head not code)???:-

Totallength/3 = LengthIn3mBays  
LengthIn3mBays - LengthIn3mBays(rounded down to whole number) = LeftOver  
if {(LeftOver \> 1.8 )  
LastBay = 2.4  
else if {  
LeftOver \< 1.8  
LastBay = 1.8  
}  
}

any help would be wicked!! 🎻
