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

50%
+0 −0
Challenges Evaluate a single variable polynomial equation

Python 3, 167 127 118 117 94 63 bytes def f(a,b): y=0 for z in range(len(a)):y+=a[z]*b**z print(y) Try it online! Close gap to @user's lambda answer! Golfed 40 bytes thanks to @user's...

posted 3y ago by General Sebast1an‭  ·  edited 3y ago by General Sebast1an‭

Answer
#7: Post edited by user avatar General Sebast1an‭ · 2021-09-21T02:36:52Z (over 3 years ago)
  • # [Python 3], <s>167</s> <s>127</s> <s>118</s> <s>117</s> 94 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>x=float(input());y,z=0,0
  • while 1:
  • &#9;try:a=float(input())
  • &#9;except:break
  • &#9;y+=a*x**z;z+=1
  • print(y)
  • </code></pre>
  • [Try it online!][TIO-ksrd0p54]
  • Golfed 40 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12772). Golfed another 9 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12782).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ksrd0p54]: https://tio.run/##XcqxDsIgEADQmfsKR6BNA1YXGj7mNJgSG0rIGTl@Hpkd3vYy036mtffqX8eJJGPKH5JKbTw3b2YD3z0e4WIdCCrs8K@BCPUZMrlHCfgGwZNHXbVuW5u8hVxiIsmqd7vcwS4GrsM63Ab8AQ "Python 3 – Try It Online"
  • # [Python 3], <s>167</s> <s>127</s> <s>118</s> <s>117</s> <s>94</s> 63 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(a,b):
  • &#9;y=0
  • &#9;for z in range(len(a)):y+=a[z]*b**z
  • &#9;print(y)
  • </code></pre>
  • [Try it online!][TIO-kttgfxko]
  • Close gap to [**@user**](https://codegolf.codidact.com/users/53837)'s [`lambda` answer](https://codegolf.codidact.com/posts/279159/283562#answer-283562)!
  • Golfed 40 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12772). Golfed another 9 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12782).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kttgfxko]: https://tio.run/##K6gsycjPM/7/PyU1TSFNI1EnSdOKi7PS1oCLMy2/SKFKITNPoSgxLz1VIyc1TyNRU9OqUts2MboqVitJS6uKi7OgKDOvRKNS83@aRrShnkGsjqGFkSYXhKNjBBIwAXON9EwhXAM9U2R5HWMgNgFrBEr8BwA "Python 3 – Try It Online"
#6: Post edited by user avatar General Sebast1an‭ · 2021-08-25T10:35:20Z (over 3 years ago)
  • # [Python 3], <s>167</s> <s>127</s> <s>118</s> 117 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>x=float(input());y,z=0,0
  • while 1:
  • &#9;try:a=float(input())
  • &#9;except:break
  • &#9;if z^0:y+=a*x**z;z+=1
  • &#9;else:y+=a;z+=1
  • print(y)
  • </code></pre>
  • [Try it online!][TIO-ksrcx59d]
  • Golfed 40 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12772). Golfed another 9 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12782).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ksrcx59d]: https://tio.run/##XcqxDsIgFIXhmfsUHYE2DVhdaHgVEzQ0JRJK8BqBl0eim8M3nJM/FtyPsLSW9eYPg9SF@ELK2FqmqsUk4L07bwepgGAqyvxlQGy@24jqlqx5AHHbUK9ClVEbnjmvax217JF/2u/52zG5gLSw1uR8ATkLOHVLd@7MBw "Python 3 – Try It Online"
  • # [Python 3], <s>167</s> <s>127</s> <s>118</s> <s>117</s> 94 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>x=float(input());y,z=0,0
  • while 1:
  • &#9;try:a=float(input())
  • &#9;except:break
  • &#9;y+=a*x**z;z+=1
  • print(y)
  • </code></pre>
  • [Try it online!][TIO-ksrd0p54]
  • Golfed 40 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12772). Golfed another 9 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12782).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ksrd0p54]: https://tio.run/##XcqxDsIgEADQmfsKR6BNA1YXGj7mNJgSG0rIGTl@Hpkd3vYy036mtffqX8eJJGPKH5JKbTw3b2YD3z0e4WIdCCrs8K@BCPUZMrlHCfgGwZNHXbVuW5u8hVxiIsmqd7vcwS4GrsM63Ab8AQ "Python 3 – Try It Online"
#5: Post edited by user avatar General Sebast1an‭ · 2021-08-25T10:32:31Z (over 3 years ago)
  • # [Python 3], <s>167</s> <s>127</s> 118 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>x=float(input());y,z=0,0
  • while 1:
  • &#9;try:a=float(input())
  • &#9;except:break
  • &#9;if z==0:y+=a;z+=1
  • &#9;else:y+=a*x**z;z+=1
  • print(y)
  • </code></pre>
  • [Try it online!][TIO-ksia37y2]
  • Golfed 40 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12772). Golfed another 9 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12782).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ksia37y2]: https://tio.run/##XcqxDsIgFIXhmfsUHYE2DVhdaHgYNDQlEkroNQIvj0Q3h284J38suB9haS3rzR8GqQvxhZSxtUxVi0nAe3feDlIBwVSU@cuA2PywEdU9WfME4rahai1UGbVZ66hlD/xpv5tnzuvvjMkFpIW1JucbyFnApVu6a2c@ "Python 3 – Try It Online"
  • # [Python 3], <s>167</s> <s>127</s> <s>118</s> 117 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>x=float(input());y,z=0,0
  • while 1:
  • &#9;try:a=float(input())
  • &#9;except:break
  • &#9;if z^0:y+=a*x**z;z+=1
  • &#9;else:y+=a;z+=1
  • print(y)
  • </code></pre>
  • [Try it online!][TIO-ksrcx59d]
  • Golfed 40 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12772). Golfed another 9 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12782).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ksrcx59d]: https://tio.run/##XcqxDsIgFIXhmfsUHYE2DVhdaHgVEzQ0JRJK8BqBl0eim8M3nJM/FtyPsLSW9eYPg9SF@ELK2FqmqsUk4L07bwepgGAqyvxlQGy@24jqlqx5AHHbUK9ClVEbnjmvax217JF/2u/52zG5gLSw1uR8ATkLOHVLd@7MBw "Python 3 – Try It Online"
#4: Post edited by user avatar General Sebast1an‭ · 2021-08-19T02:04:30Z (over 3 years ago)
  • # [Python 3], <s>167</s> 127 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>x=float(input());y,z=0,0
  • while 1:
  • &#9;try:
  • &#9;&#9;a=float(input())
  • &#9;&#9;if z==0:y+=a;z+=1;continue
  • &#9;&#9;y+=a*x**z;z+=1
  • &#9;except:break
  • print(y)
  • </code></pre>
  • [Try it online!][TIO-kshok75l]
  • Golfed 40 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12772). Golfed another 9 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12782).
  • >The first revision is now readily available to be ran in [MarkFuncs](https://github.com/JoyrenceMatthewAgas/MarkFuncs). It's a cool program I made that I hope you'll enjoy using. Please read the tutorial before running it if you don't know how it works.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kshok75l]: https://tio.run/##XYpBDsIgFAXXcIougTYErG4gHAYbmhIbIOQ3ApdHdOli3mLmpQpHDGvvxexntEB8SBcQSnVdmhGLwO/Dn26SCiPIdSyyf8@h/D41Y4Sqs7G6zUbqLQbw4XIjfiUrjLVfwciVzSVQz@zsC6fsA5BKe5f8gSUX@DZYB3cuPg "Python 3 – Try It Online"
  • # [Python 3], <s>167</s> <s>127</s> 118 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>x=float(input());y,z=0,0
  • while 1:
  • &#9;try:a=float(input())
  • &#9;except:break
  • &#9;if z==0:y+=a;z+=1
  • &#9;else:y+=a*x**z;z+=1
  • print(y)
  • </code></pre>
  • [Try it online!][TIO-ksia37y2]
  • Golfed 40 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12772). Golfed another 9 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12782).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ksia37y2]: https://tio.run/##XcqxDsIgFIXhmfsUHYE2DVhdaHgYNDQlEkroNQIvj0Q3h284J38suB9haS3rzR8GqQvxhZSxtUxVi0nAe3feDlIBwVSU@cuA2PywEdU9WfME4rahai1UGbVZ66hlD/xpv5tnzuvvjMkFpIW1JucbyFnApVu6a2c@ "Python 3 – Try It Online"
#3: Post edited by user avatar General Sebast1an‭ · 2021-08-19T02:03:30Z (over 3 years ago)
  • # [Python 3], <s>167</s> 127 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>x=float(input());y,z=0,0
  • while 1:
  • &#9;try:
  • &#9;&#9;a=float(input())
  • &#9;&#9;if z==0:y+=a;z+=1;continue
  • &#9;&#9;y+=a*x**z;z+=1
  • &#9;except:break
  • print(y)
  • </code></pre>
  • [Try it online!][TIO-kshok75l]
  • Golfed 40 bytes thanks to [user](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12772).
  • >The first revision is now readily available to be ran in [MarkFuncs](https://github.com/JoyrenceMatthewAgas/MarkFuncs). It's a cool program I made that I hope you'll enjoy using. Please read the tutorial before running it if you don't know how it works.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kshok75l]: https://tio.run/##XYpBDsIgFAXXcIougTYErG4gHAYbmhIbIOQ3ApdHdOli3mLmpQpHDGvvxexntEB8SBcQSnVdmhGLwO/Dn26SCiPIdSyyf8@h/D41Y4Sqs7G6zUbqLQbw4XIjfiUrjLVfwciVzSVQz@zsC6fsA5BKe5f8gSUX@DZYB3cuPg "Python 3 – Try It Online"
  • # [Python 3], <s>167</s> 127 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>x=float(input());y,z=0,0
  • while 1:
  • &#9;try:
  • &#9;&#9;a=float(input())
  • &#9;&#9;if z==0:y+=a;z+=1;continue
  • &#9;&#9;y+=a*x**z;z+=1
  • &#9;except:break
  • print(y)
  • </code></pre>
  • [Try it online!][TIO-kshok75l]
  • Golfed 40 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12772). Golfed another 9 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12782).
  • >The first revision is now readily available to be ran in [MarkFuncs](https://github.com/JoyrenceMatthewAgas/MarkFuncs). It's a cool program I made that I hope you'll enjoy using. Please read the tutorial before running it if you don't know how it works.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kshok75l]: https://tio.run/##XYpBDsIgFAXXcIougTYErG4gHAYbmhIbIOQ3ApdHdOli3mLmpQpHDGvvxexntEB8SBcQSnVdmhGLwO/Dn26SCiPIdSyyf8@h/D41Y4Sqs7G6zUbqLQbw4XIjfiUrjLVfwciVzSVQz@zsC6fsA5BKe5f8gSUX@DZYB3cuPg "Python 3 – Try It Online"
#2: Post edited by user avatar General Sebast1an‭ · 2021-08-18T16:01:45Z (over 3 years ago)
  • # [Python 3], 167 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>n=[]
  • while True:
  • &#9;try:a=float(input());n.append(a);continue
  • &#9;except:break
  • x=float(input());y=0
  • for i in range(len(n)):
  • &#9;if i==0:y+=n[i];continue
  • &#9;y+=n[i]*x**i
  • print(y)
  • </code></pre>
  • [Try it online!][TIO-ksgudvzh]
  • Not exactly "golfy", but it's more manageable than C. lmao
  • The form of input uses a `while` loop to take the array of numbers, simply `float`s, then the inputting stops if the input can't be converted into a `float`. Then takes another input for basing the calculation. And yes, I wrote the variable names as `n` and `x`.
  • >The first revision is now readily available to be ran in [MarkFuncs](https://github.com/JoyrenceMatthewAgas/MarkFuncs). It's a cool program I made that I hope you'll enjoy using. Please read the tutorial before running it if you don't know how it works.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ksgudvzh]: https://tio.run/##Xc2xDoIwFAXQmfcVHVtMCIguJf0LN8JQ8SEvktemKZF@fe3gYBzOcpN7r09xddznzGac4L3ShuIWdtRQxZC0NcvmbJTEfo9SqYEb6z3yQ1o1zI4j8Y5Q4TGjj/oe0L7g@O8k08LigiBBLILlJ8oNWbJS5YUWQca0Op0MjzT9jH6T@qhrAh@Io0wq565p4Vz0xaWw0DXXDw "Python 3 – Try It Online"
  • # [Python 3], <s>167</s> 127 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>x=float(input());y,z=0,0
  • while 1:
  • &#9;try:
  • &#9;&#9;a=float(input())
  • &#9;&#9;if z==0:y+=a;z+=1;continue
  • &#9;&#9;y+=a*x**z;z+=1
  • &#9;except:break
  • print(y)
  • </code></pre>
  • [Try it online!][TIO-kshok75l]
  • Golfed 40 bytes thanks to [user](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4089#comment-12772).
  • >The first revision is now readily available to be ran in [MarkFuncs](https://github.com/JoyrenceMatthewAgas/MarkFuncs). It's a cool program I made that I hope you'll enjoy using. Please read the tutorial before running it if you don't know how it works.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kshok75l]: https://tio.run/##XYpBDsIgFAXXcIougTYErG4gHAYbmhIbIOQ3ApdHdOli3mLmpQpHDGvvxexntEB8SBcQSnVdmhGLwO/Dn26SCiPIdSyyf8@h/D41Y4Sqs7G6zUbqLQbw4XIjfiUrjLVfwciVzSVQz@zsC6fsA5BKe5f8gSUX@DZYB3cuPg "Python 3 – Try It Online"
#1: Initial revision by user avatar General Sebast1an‭ · 2021-08-18T02:23:15Z (over 3 years ago)
# [Python 3], 167 bytes

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

<pre><code>n=[]
while True:
&#9;try:a=float(input());n.append(a);continue
&#9;except:break
x=float(input());y=0
for i in range(len(n)):
&#9;if i==0:y+=n[i];continue
&#9;y+=n[i]*x**i
print(y)
</code></pre>

[Try it online!][TIO-ksgudvzh]

Not exactly "golfy", but it's more manageable than C. lmao

The form of input uses a `while` loop to take the array of numbers, simply `float`s, then the inputting stops if the input can't be converted into a `float`. Then takes another input for basing the calculation. And yes, I wrote the variable names as `n` and `x`.

>The first revision is now readily available to be ran in [MarkFuncs](https://github.com/JoyrenceMatthewAgas/MarkFuncs). It's a cool program I made that I hope you'll enjoy using. Please read the tutorial before running it if you don't know how it works.

[Python 3]: https://docs.python.org/3/
[TIO-ksgudvzh]: https://tio.run/##Xc2xDoIwFAXQmfcVHVtMCIguJf0LN8JQ8SEvktemKZF@fe3gYBzOcpN7r09xddznzGac4L3ShuIWdtRQxZC0NcvmbJTEfo9SqYEb6z3yQ1o1zI4j8Y5Q4TGjj/oe0L7g@O8k08LigiBBLILlJ8oNWbJS5YUWQca0Op0MjzT9jH6T@qhrAh@Io0wq565p4Vz0xaWw0DXXDw "Python 3 – Try It Online"