Post History
Python 3, 76 71 bytes Saved 5 bytes thanks to user def f(p,n):l=[n*p//q for(p,q)in p if n%q<1];return f(p,l[0])if l else n Try it online! This code assumes that the fractions are given a...
Answer
#2: Post edited
# [Python 3], 76 bytes- <!-- language-all: lang-python -->
def f(p,n):l=[n*p//q for(p,q)in p if n%q==0];return n if l==[]else f(p,l[0])[Try it online!][TIO-komlpd7s]- This code assumes that the fractions are given as completely cancelled pairs of integers.
- [Python 3]: https://docs.python.org/3/
[TIO-komlpd7s]: https://tio.run/##ZVJdb4MgFH33V9yQLJGFpAIFPxZe97x3Y4hZcTOxaJU@LEt/ewdqW5uZIHK8nHMuh@HHffeWX68H00ATD8TiolOlfR12uxM0/eihE24tDNA2YF9OSiXV22jcebRgA9YpVVamm8y8vSuTCs9kzkwuDq/PejK4iMA/w9jaB0jA2INCBSC8@Ys@6mkyBxS4m3ttiYax/xrrI6oIPMDWDmeHKgxKbdD@7GYYZlvovW47T4ijKPg61q2NVz@3LRQU/MJdooAyTjMiBCYQC8LDRMm8opSwBU2xd7IaKIAmuaRcpJx7cNUvgLMs2/uR0Vymku1TJrPcF6UJh8uTA/bfAfdKTxIsl1tyKSR9JuH/SfbC@@erc7p2QmmYuW9h0xH1fW7lUrYVo0IycYlmOX8rwIG/E@X9/B6ZsMcnr5ZTvlmMnY/Ap6q1rY9G6xAa0joEojVaapd0ousf "Python 3 – Try It Online"
- # [Python 3], <s>76</s> 71 bytes
- Saved 5 bytes thanks to [user](https://codegolf.codidact.com/comments/thread/3115#comment-10312)
- <!-- language-all: lang-python -->
- def f(p,n):l=[n*p//q for(p,q)in p if n%q<1];return f(p,l[0])if l else n
- [Try it online!][TIO-kt41kxaz]
- This code assumes that the fractions are given as completely cancelled pairs of integers.
- [Python 3]: https://docs.python.org/3/
- [TIO-kt41kxaz]: https://tio.run/##ZVJda4MwFH33V1wCAzMCbZImfmy@7nnvIkHWuAk2Wk0fxuhv764fbS0VYszJ9Zxzc9L9@p/Wyctlbyuowo45mjZZ7l67zeYIVdsjdKS1gw7qCtzL8Z0Xb731p95N5U2@LSjuNGCbwYKbeLwdfDi@vsrB0jQAfLq@dneQgXX7jKRA6GqXfJbDYPdklKputTnp@va7Lw@kYHAHa9edPCkoZNkKbU9@gmc75KOsGySkQTD6OpS1Cxc/1184ZPAHN4kU8jCKmVKUQaiYHCfOphXnTMxoRNHJYiAFvk00lyqSEsFFPwUp4niHI@aJjrTYRULHCRZFWwnnBwfi2YFEpQcJkeg1uVaaP5LIZ5KdQv9ycc6XTjgfZ4ktrDri2OdaLhJrMa60UOdgksMLAR7wOuS387tnIu6fsphP@Wox9BgBpmqMKw/WmDE0YswYiDFkrp3TCS7/ "Python 3 – Try It Online"
#1: Initial revision
# [Python 3], 76 bytes <!-- language-all: lang-python --> def f(p,n):l=[n*p//q for(p,q)in p if n%q==0];return n if l==[]else f(p,l[0]) [Try it online!][TIO-komlpd7s] This code assumes that the fractions are given as completely cancelled pairs of integers. [Python 3]: https://docs.python.org/3/ [TIO-komlpd7s]: https://tio.run/##ZVJdb4MgFH33V9yQLJGFpAIFPxZe97x3Y4hZcTOxaJU@LEt/ewdqW5uZIHK8nHMuh@HHffeWX68H00ATD8TiolOlfR12uxM0/eihE24tDNA2YF9OSiXV22jcebRgA9YpVVamm8y8vSuTCs9kzkwuDq/PejK4iMA/w9jaB0jA2INCBSC8@Ys@6mkyBxS4m3ttiYax/xrrI6oIPMDWDmeHKgxKbdD@7GYYZlvovW47T4ijKPg61q2NVz@3LRQU/MJdooAyTjMiBCYQC8LDRMm8opSwBU2xd7IaKIAmuaRcpJx7cNUvgLMs2/uR0Vymku1TJrPcF6UJh8uTA/bfAfdKTxIsl1tyKSR9JuH/SfbC@@erc7p2QmmYuW9h0xH1fW7lUrYVo0IycYlmOX8rwIG/E@X9/B6ZsMcnr5ZTvlmMnY/Ap6q1rY9G6xAa0joEojVaapd0ousf "Python 3 – Try It Online"