Skip to main content
added 356 characters in body
Source Link

Python 3.8, 35 34 bytes

def l(i): if i:print(i);l(int(i)) 

Older python 3.8 only code

i=input() while i:print(i:=int(i)) 

Try me!Try me!

Explination:

While this ties the best python 3 answer thanks xnor for saving me a byte

This uses a few interesting properties to achieve what it does:

  1. The input received is always a string, thus the while-loop will start regardless if its a 1 or 0

    The input received is always a string when from a user input, thus the while-loop will start regardless if its a 1 or 0

  2. Inside the loop, we print the number for the first time, and simultaneously using the walrus operator which was introduced in python 3.8, we assign the integer value to i.

    Inside the loop, we print the number for the first time, and simultaneously using the walrus operator which was introduced in python 3.8, we assign the integer value to i. Using recursion, this code can now work in all versions of python 3, while it isn't a major improvement in bytes count, I'd still count making the code work in more versions an improvement!

  3. Now, the value, if zero, is now converted from "0" to 0, meaning the loop will exit, otherwise if its 1, it keeps going!

    Now, the value, if zero, is now converted from "0" to 0, meaning the loop will exit, otherwise if its 1, it keeps going!

I am not sure if this can be shortened, I have tried using a lambda, which is where I learned you can't merge a lambda and a while loophard to get lambdas to work, but every attempt ended up with more lines due to having to use recursion, if anyone has any ideas I think there is a byte or two theream all ears! Meanwhile I will try to keep pushing this, the new version feels like it has more that can be shanked.pushed

Python 3.8, 35 34 bytes

i=input() while i:print(i:=int(i)) 

Try me!

Explination:

While this ties the best python 3 answer thanks xnor for saving me a byte

This uses a few interesting properties to achieve what it does:

  1. The input received is always a string, thus the while-loop will start regardless if its a 1 or 0
  2. Inside the loop, we print the number for the first time, and simultaneously using the walrus operator which was introduced in python 3.8, we assign the integer value to i.
  3. Now, the value, if zero, is now converted from "0" to 0, meaning the loop will exit, otherwise if its 1, it keeps going!

I am not sure if this can be shortened, I tried using a lambda, which is where I learned you can't merge a lambda and a while loop, but I think there is a byte or two there that can be shanked.

Python 3, 35 34 bytes

def l(i): if i:print(i);l(int(i)) 

Older python 3.8 only code

i=input() while i:print(i:=int(i)) 

Try me!

Explination:

While this ties the best python 3 answer thanks xnor for saving me a byte

This uses a few interesting properties to achieve what it does:

  1. The input received is always a string when from a user input, thus the while-loop will start regardless if its a 1 or 0

  2. Inside the loop, we print the number for the first time, and simultaneously using the walrus operator which was introduced in python 3.8, we assign the integer value to i. Using recursion, this code can now work in all versions of python 3, while it isn't a major improvement in bytes count, I'd still count making the code work in more versions an improvement!

  3. Now, the value, if zero, is now converted from "0" to 0, meaning the loop will exit, otherwise if its 1, it keeps going!

I have tried hard to get lambdas to work, but every attempt ended up with more lines due to having to use recursion, if anyone has any ideas I am all ears! Meanwhile I will try to keep pushing this, the new version feels like it has more that can be pushed

added 51 characters in body
Source Link

Python 3.8, 3535 34 bytes

i=input() while( i):print(i:=int(i)) 

Try me!Try me!

Explination:

While this ties the best python 3 answer, itWhile this ties the best python 3 answer thanks xnor for saving me a byte

This uses a few interesting properties to achieve what it does:

  1. The input received is always a string, thus the while-loop will start regardless if its a 1 or 0
  2. Inside the loop, we print the number for the first time, and simultaneously using the walrus operator which was introduced in python 3.8, we assign the integer value to i.
  3. Now, the value, if zero, is now converted from "0" to 0, meaning the loop will exit, otherwise if its 1, it keeps going!

I am not sure if this can be shortened, I tried using a lambda, which is where I learned you can't merge a lambda and a while loop, but I think there is a byte or two there that can be shanked.

Python 3.8, 35 bytes

i=input() while(i):print(i:=int(i)) 

Try me!

Explination:

While this ties the best python 3 answer, it uses a few interesting properties to achieve what it does:

  1. The input received is always a string, thus the while-loop will start regardless if its a 1 or 0
  2. Inside the loop, we print the number for the first time, and simultaneously using the walrus operator which was introduced in python 3.8, we assign the integer value to i.
  3. Now, the value, if zero, is now converted from "0" to 0, meaning the loop will exit, otherwise if its 1, it keeps going!

I am not sure if this can be shortened, I tried using a lambda, which is where I learned you can't merge a lambda and a while loop, but I think there is a byte or two there that can be shanked.

Python 3.8, 35 34 bytes

i=input() while i:print(i:=int(i)) 

Try me!

Explination:

While this ties the best python 3 answer thanks xnor for saving me a byte

This uses a few interesting properties to achieve what it does:

  1. The input received is always a string, thus the while-loop will start regardless if its a 1 or 0
  2. Inside the loop, we print the number for the first time, and simultaneously using the walrus operator which was introduced in python 3.8, we assign the integer value to i.
  3. Now, the value, if zero, is now converted from "0" to 0, meaning the loop will exit, otherwise if its 1, it keeps going!

I am not sure if this can be shortened, I tried using a lambda, which is where I learned you can't merge a lambda and a while loop, but I think there is a byte or two there that can be shanked.

Source Link

Python 3.8, 35 bytes

i=input() while(i):print(i:=int(i)) 

Try me!

Explination:

While this ties the best python 3 answer, it uses a few interesting properties to achieve what it does:

  1. The input received is always a string, thus the while-loop will start regardless if its a 1 or 0
  2. Inside the loop, we print the number for the first time, and simultaneously using the walrus operator which was introduced in python 3.8, we assign the integer value to i.
  3. Now, the value, if zero, is now converted from "0" to 0, meaning the loop will exit, otherwise if its 1, it keeps going!

I am not sure if this can be shortened, I tried using a lambda, which is where I learned you can't merge a lambda and a while loop, but I think there is a byte or two there that can be shanked.