List math problem

Ive been trying to get chap gbt to work this out but it cant. I also was getting real carried away with geometry to work it out as the result will be pulling from points but I cant work this out.

What I’m trying to do. Say I have a list of varied increasing numbers and an input number. I’m trying to get the equal to or less then number in the list. Then add the inputted number to that and get the next equal to or greater then number in the list through the list.

for instance you have

1
2
5
10
20
30
50
60

Your inputted number is 15. 10 is the next equal to or less then number so thats one result. Next result is 10+15=25. The next equal to or less then number to that is 20. 20+15=35. The next equal to or less then number in the list is 30 and so on. Anyone know how to do this with python or dynamo nodes?

Because I cant workout that problem. I’ve made all of this as a round about :rofl:

nums = [1,2,5,10,20,40]

summed = []

check = 15
ind = 0

for n in nums:
    if check < n:
        break
    else:
        ind += 1

for n in nums[ind-1:]:
    summed.append(check+ n)

print(summed)
2 Likes

Thanks Gavin, gave it a bash but not sure the results I’m getting. With the example below I should get the output 17490 and 34445. First number is equal or lower than 19000. So 17490+19000=36,490 The next number equal to or lower than 36490 is 34445 and so on. I may have put the code in wrong to use in dynamo.

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

# Place your code below this line
nums = IN[0]

summed = []

check = IN[1]
ind = 0

for n in nums:
    if check < n:
        break
    else:
        ind += 1

for n in nums[ind-1:]:
    summed.append(check+ n)

printnums = [1,2,5,10,20,40]

summed = []

check = 15
ind = 0

for n in nums:
    if check < n:
        break
    else:
        ind += 1

for n in nums[ind-1:]:
    summed.append(check+ n)
# Assign your output to the OUT variable.
OUT = summed

OK, misread post to start… But think I got it now

RandomList = IN[0]
InputNumber = IN[1]

NewRandomList = []

for index, i in enumerate(RandomList):
	if i > InputNumber:
		NewRandomList.append(RandomList[index -1])
		InputNumber += RandomList[index -1]

OUT = NewRandomList

1 Like

Looks like you put two sets of the code in. Remove the bottom one as that redeclares check as 15.

Here’s a one liner, assuming the list is sorted and covers the case where n is less than the minimum

from bisect import bisect

n = 15
nums = [1, 2, 3, 10, 20, 30, 50, 60]

out = (
    [i + n for i in nums]
    if not bisect(nums, n)
    else [i + n for i in nums[bisect(nums, n) - 1 :]]
)
2 Likes

Thank you! Can get rid of all these nodes with one simple one

1 Like

Thanks for the help. If your interested. It didn’t seem to get the next number correctly when used with this list. 34470+18500=52,970. Next lowest number from that in the list below is 51810.

Thanks, gave it a fix but got this

Thanks, gave this a bash but didn’t seem to give the right result.

Maybe write the list of numbers here with expected outcomes?

1 Like

Sure

Say our input number is 10

our list of numbers is 3, 5, 8, 9, 12, 13, 17, 22, 25, 28, 31, 35, 38

The output would be 9, 17, 25, 31, 38

10 next below to that is 9
9+10 = 19 next below is 17
17+10 = 27 next below 25
25+10 = 35 next below 31
31+10 = 41 next below 38

The numbers in reality will be much larger and have a lot more numbers in between the input number. Will always be some varied list of numbers but the same formula will be used

RandomList = [3, 5, 8, 9, 12, 13, 17, 22, 25, 28, 31, 35, 38]
InputNumber = 10
NumberAdded = InputNumber
NewRandomList = []

for index, i in enumerate(RandomList):
        if i >= NumberAdded:
                x = RandomList[index -1]
                NewRandomList.append(x)
                NumberAdded = x + InputNumber

print (NewRandomList)
2 Likes

Edit: Looks like I misunderstood the assignment, as I was getting the 'next lowest in the sequence built from the original step value. You want the ‘next lowest from the previous value + the step value’. @Alien’s solution would be the way I’d go about that.

It would likely help if we had the failing dataset. Otherwise we can’t really see ‘why’ it failed.

This design script works with the original dataset provided:

def findLowerSequence(check: double, rng: double[])
{
	steps = (check..#(rng[-1] / check) + 1..check);
	inserted = List.AddItemToEnd(steps@L1<1>, rng);
	sorted = List.Sort(inserted);
	reversed = List.Reverse(sorted@L2<1>);
	indx = List.IndexOf(reversed@L2<1>, steps@L1<1>)+1;
	vals = List.GetItemAtIndex(reversed@L2<1>, indx@L1<1>);
	result = List.UniqueItems(vals);
	return result;
};

As does this python:

step = IN[0]
valsList = IN[1]
findings = []

if step < valsList[0]:
    checkNum = valsList[0]
    findings.append(checkNum)
else:checkNum = step

steps = int(valsList[-1]/step)+1
tests = [(i+1)*step for i in range(steps-1)]

for i in tests:
    allVals = [i for i in valsList]
    allVals.append(i)
    allVals.sort()
    indx = allVals.index(i)-1
    findings.append(allVals[indx])

findings.append(valsList[-1])

OUT = []
OUT = [i for i in findings if i not in OUT]
1 Like

Thanks Jacob and Alien.

Jacob the dataset is always varying. However can make up a list pretty quick in dynamo to test it out.

Seems like Aliens is working atm with varied inputs!

Last lot of code misses off the end number… This includes it:

RandomList = [3, 5, 8, 9, 12, 13, 17, 22, 25, 28, 31, 35, 38]
InputNumber = 10
NumberAdded = InputNumber
NewRandomList = []

for index, i in enumerate(RandomList):
        if i >= NumberAdded:
                x = RandomList[index -1]
                NewRandomList.append(x)
                NumberAdded = x + InputNumber
        if index == (len(RandomList)- 1):
            if i < NumberAdded:
                NewRandomList.append(i)


print (NewRandomList)
3 Likes

Amazing thanks Alien. Pretty cool. Helps this door types schedule script work out the correct size views to go on sheets now.

2 Likes

Nice. Fancy explaining roughly how that works?

1 Like

For sure! Well I hope you mean the whole script itself :sweat_smile: Otherwise I’m really going to blabber on below.

The company I started working for does type schedules in a content phase prior to the existing phase to tag the element and use BIM qualities from it I’m guessing. So I thought this would be super fun to try automate! Just professing this by saying I have no degree in anything and learnt dynamo playing around for many a hours. So the ways I go about things arnt too practical but get the job done for varying instances.

1 = User inputs
image

2= Collect placed doors in the project, get unique and organizing by company door naming standard for the sheets and to number type marks if wanted. Which became more complicated then I thought with the company naming standard. Went for exterior doors first, then interior. Then inside of that fire doors or vision panels/kick plates first. Double doors are populating before single panel doors but I got sick of it :rofl: Could actually use the family of the door to group that properly thinking now…

3= Gets the widths of the doors to space them out correctly and place them in a wall. The spacing required by this dictates how long the wall should be too and draws it for the doors to be placed in the right phase out from the project at the lowest level, testing on some projects there were a few coordinate issues to work through. Need the right node for the job. The wall height covers the door height and goes down below to allow room for the tag, this also dictates the view crop box height which is slightly cropped in from the wall to have clean edges.

4= Is where you smart fellas came in. The list of numbers is a point between each door. The input number is the max sheet length before the door needs to start at a new section on the sheet. Which accounts for horizontal and vertical sheet sizes. When I have those points. I draw a line and extrude it backwards to the point before it. Then do an intersection to get the crop box around each view. I’m pretty sure that’s whats happening. :joy:

5= With those view crop box curves I can create an elevation around each door set. This uses a method I found ages ago on the internet someone kindly wrote. Positions the point to the exterior side of the doors for the elevation marker. In my previous post you can see the points being worked out. Few extra points in there. Why I dono :grin:

6= Throwing down some tags after some needed transaction end nodes, naming some views and chucking things to the right phase.

7= Something I worked out awhile ago to handle just about all sheet number conventions. Basically works backwards on a sheet number to find something that’s not the number to understand the prefix and populate the right sheet numbers.

8= Figures out how many sheets to create and chucks the views on a sheet.

9= Dimensions the doors. I couldn’t figure out how to dimension to the actual element itself on edges I wanted and gave up. To hard basket. So just got the edges I wanted and draw detail lines to dimension to. Got the lines I wanted by bounding boxing a door. Reducing the percentage of the bounding box. Intersecting that with the door. This generally gave me the ouster door frame. Then intersected that with the rest of the exploded door parts to just get the leafs of doors lines. If it didn’t find one element for the outer frame. It would find the outer frame by intersecting the corner part of the original size bounding box. Then with the leafs, filter out frames and vision panels. Got a reasonable amount of lines to work out your overall and leaf dimensions. Not perfect but for the user to review after.

Gives you something like below. If something dosn’t make sense let me know or needs a better explanation let me know! Graph itself runs pretty fast considering how big it is too.

3 Likes