Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

75%
+4 −0
Challenges Length of a Sumac Sequence

Python 3, 49 47 44 35 bytes a=lambda x,y:+(x>=0)and(1+a(y,x-y)) Try it online! -3 bytes thanks to @Hakerh400‭ -9 bytes thanks to @Jo King‭ Python 2, 50 bytes x,y=input() a=0 while...

posted 4y ago by Quintec‭  ·  edited 4y ago by Quintec‭

Answer
#7: Post edited by user avatar Quintec‭ · 2021-01-05T16:25:57Z (almost 4 years ago)
  • # [Python 3], <strike> 49 47 44</strike> 35 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:+(x>=0)and(1+a(y,x-y))
  • [Try it online!][TIO-khlfbe2n]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khlfbe2n]: https://tio.run/##VcxNCsIwEEDhvacYcDOhE5hJUtoK9S4jXShoLNJFcvrYHwm4/Xi8OS/3d/Sl6PjU121SSJQvDabryEbjhNIoZko2G1PmzyMuqCiOCToxBuAM7akyCwW36cq@cstMYRiOOlT2fUf74r/2ZMX1v4lUto78Ea/M5Qs "Python 3 – Try It Online"
  • _-3 bytes thanks to @Hakerh400‭_
  • _-9 bytes thanks to @Hakerh400‭_
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
  • # [Python 3], <strike> 49 47 44</strike> 35 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:+(x>=0)and(1+a(y,x-y))
  • [Try it online!][TIO-khlfbe2n]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khlfbe2n]: https://tio.run/##VcxNCsIwEEDhvacYcDOhE5hJUtoK9S4jXShoLNJFcvrYHwm4/Xi8OS/3d/Sl6PjU121SSJQvDabryEbjhNIoZko2G1PmzyMuqCiOCToxBuAM7akyCwW36cq@cstMYRiOOlT2fUf74r/2ZMX1v4lUto78Ea/M5Qs "Python 3 – Try It Online"
  • _-3 bytes thanks to @Hakerh400‭_
  • _-9 bytes thanks to @Jo King‭_
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
#6: Post edited by user avatar Quintec‭ · 2020-11-17T03:35:34Z (about 4 years ago)
  • # [Python 3], <strike>49 47</strike> 44 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:(x>=0)*(1if y<0else 1+a(y,x-y))
  • _-3 bytes thanks to @Hakerh400‭_
  • [Try it online!][TIO-khkxumxy]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khkxumxy]: https://tio.run/##K6gsycjPM/7/P9E2JzE3KSVRoUKn0kqjws7WQFNLwzAzTaHSxiA1pzhVwVA7UaNSp0K3UlPzf0FRZl6JRqKGoZGBjoK5IVAEAA "Python 3 – Try It Online"
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
  • # [Python 3], <strike> 49 47 44</strike> 35 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:+(x>=0)and(1+a(y,x-y))
  • [Try it online!][TIO-khlfbe2n]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khlfbe2n]: https://tio.run/##VcxNCsIwEEDhvacYcDOhE5hJUtoK9S4jXShoLNJFcvrYHwm4/Xi8OS/3d/Sl6PjU121SSJQvDabryEbjhNIoZko2G1PmzyMuqCiOCToxBuAM7akyCwW36cq@cstMYRiOOlT2fUf74r/2ZMX1v4lUto78Ea/M5Qs "Python 3 – Try It Online"
  • _-3 bytes thanks to @Hakerh400‭_
  • _-9 bytes thanks to @Hakerh400‭_
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
#5: Post edited by user avatar Moshi‭ · 2020-11-16T19:29:32Z (about 4 years ago)
  • # [Python 3], ~~49 47~~ 44 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:(x>=0)*(1if y<0else 1+a(y,x-y))
  • _-3 bytes thanks to @Hakerh400‭_
  • [Try it online!][TIO-khkxumxy]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khkxumxy]: https://tio.run/##K6gsycjPM/7/P9E2JzE3KSVRoUKn0kqjws7WQFNLwzAzTaHSxiA1pzhVwVA7UaNSp0K3UlPzf0FRZl6JRqKGoZGBjoK5IVAEAA "Python 3 – Try It Online"
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
  • # [Python 3], <strike>49 47</strike> 44 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:(x>=0)*(1if y<0else 1+a(y,x-y))
  • _-3 bytes thanks to @Hakerh400‭_
  • [Try it online!][TIO-khkxumxy]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khkxumxy]: https://tio.run/##K6gsycjPM/7/P9E2JzE3KSVRoUKn0kqjws7WQFNLwzAzTaHSxiA1pzhVwVA7UaNSp0K3UlPzf0FRZl6JRqKGoZGBjoK5IVAEAA "Python 3 – Try It Online"
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
#4: Post edited by user avatar Quintec‭ · 2020-11-16T19:27:07Z (about 4 years ago)
  • # [Python 3], ~~49~~ 47 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:0if x<0else 1if y<0else 1+a(y,x-y)
  • [Try it online!][TIO-khkt9bm0]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khkt9bm0]: https://tio.run/##K6gsycjPM/7/P9E2JzE3KSVRoUKn0sogM02hwsYgNac4VcEQyK6EsbUTNSp1KnQrNf8XFGXmlWgkahgaGegomBtqav4HAA "Python 3 – Try It Online"
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
  • # [Python 3], ~~49 47~~ 44 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:(x>=0)*(1if y<0else 1+a(y,x-y))
  • _-3 bytes thanks to @Hakerh400‭_
  • [Try it online!][TIO-khkxumxy]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khkxumxy]: https://tio.run/##K6gsycjPM/7/P9E2JzE3KSVRoUKn0kqjws7WQFNLwzAzTaHSxiA1pzhVwVA7UaNSp0K3UlPzf0FRZl6JRqKGoZGBjoK5IVAEAA "Python 3 – Try It Online"
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
#3: Post edited by user avatar Quintec‭ · 2020-11-16T17:18:18Z (about 4 years ago)
  • # [Python 3], <s>49</s> 47 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:0if x<0else 1if y<0else 1+a(y,x-y)
  • [Try it online!][TIO-khkt9bm0]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khkt9bm0]: https://tio.run/##K6gsycjPM/7/P9E2JzE3KSVRoUKn0sogM02hwsYgNac4VcEQyK6EsbUTNSp1KnQrNf8XFGXmlWgkahgaGegomBtqav4HAA "Python 3 – Try It Online"
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
  • # [Python 3], ~~49~~ 47 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:0if x<0else 1if y<0else 1+a(y,x-y)
  • [Try it online!][TIO-khkt9bm0]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khkt9bm0]: https://tio.run/##K6gsycjPM/7/P9E2JzE3KSVRoUKn0sogM02hwsYgNac4VcEQyK6EsbUTNSp1KnQrNf8XFGXmlWgkahgaGegomBtqav4HAA "Python 3 – Try It Online"
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
#2: Post edited by user avatar Quintec‭ · 2020-11-16T17:17:45Z (about 4 years ago)
spaces
  • # [Python 3], 49 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:0if x<0 else 1if y<0 else 1+a(y,x-y)
  • Independently arrived at, but basically exact same format as test.
  • [Try it online!][TIO-khkt32em]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khkt32em]: https://tio.run/##K6gsycjPM/7/P9E2JzE3KSVRoUKn0sogM02hwsZAITWnOFXBEMiphHO0EzUqdSp0KzX/FxRl5pVoJGoYGhnoKJgbamr@BwA "Python 3 – Try It Online"
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
  • # [Python 3], <s>49</s> 47 bytes
  • <!-- language-all: lang-python -->
  • a=lambda x,y:0if x<0else 1if y<0else 1+a(y,x-y)
  • [Try it online!][TIO-khkt9bm0]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-khkt9bm0]: https://tio.run/##K6gsycjPM/7/P9E2JzE3KSVRoUKn0sogM02hwsYgNac4VcEQyK6EsbUTNSp1KnQrNf8XFGXmlWgkahgaGegomBtqav4HAA "Python 3 – Try It Online"
  • # [Python 2], 50 bytes
  • <!-- language-all: lang-python -->
  • x,y=input()
  • a=0
  • while x>0:x,y,a=y,x-y,a+1
  • print(a)
  • An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.
  • [Try it online!][TIO-khkt3pl0]
  • [Python 2]: https://docs.python.org/2/
  • [TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"
#1: Initial revision by user avatar Quintec‭ · 2020-11-16T17:13:27Z (about 4 years ago)
# [Python 3], 49 bytes

<!-- language-all: lang-python -->

    a=lambda x,y:0if x<0 else 1if y<0 else 1+a(y,x-y)

Independently arrived at, but basically exact same format as test.

[Try it online!][TIO-khkt32em]

[Python 3]: https://docs.python.org/3/
[TIO-khkt32em]: https://tio.run/##K6gsycjPM/7/P9E2JzE3KSVRoUKn0sogM02hwsZAITWnOFXBEMiphHO0EzUqdSp0KzX/FxRl5pVoJGoYGhnoKJgbamr@BwA "Python 3 – Try It Online"

# [Python 2], 50 bytes

<!-- language-all: lang-python -->

    x,y=input()
    a=0
    while x>0:x,y,a=y,x-y,a+1
    print(a)

An alternate solution I also came up with that I swear I should be able to make shorter, but can't think of it currently.

[Try it online!][TIO-khkt3pl0]

[Python 2]: https://docs.python.org/2/
[TIO-khkt3pl0]: https://tio.run/##K6gsycjPM/r/v0Kn0jYzr6C0REOTK9HWgKs8IzMnVaHCzsAKKKOTaFupU6ELpLUNuQqKMvNKNBI1//83NDLQMTcEAA "Python 2 – Try It Online"