User:Lemonz/CodeDotGolf

From Esolang
Jump to navigation Jump to search

My solutions to challenges on Code Golf

Fizz Buzz

Language: Python
Size (in bytes): 100
Code:

for i in range(1,101):
 o=""
 if i%3==0:o+="Fizz"
 if i%5==0:o+="Buzz"
 if o:print(o)
 else:print(i)

Foo Fizz Buzz Bar

Language: Python
Size (in bytes): 141
Code:

for i in range(1,1001):
 o=""
 if i%2==0:o+="Foo"
 if i%3==0:o+="Fizz"
 if i%5==0:o+="Buzz"
 if i%7==0:o+="Bar"
 if o:print(o)
 else:print(i)

Quine

At this point you know what language Size (still in bytes): 34 Code:

exec(s:="print('exec(s:=%r)'%s)")

Also, when trying to write a page for Irregular Expression, I accidentally golfed the Quine with a 4 byte Quine, however it does take one input so its not really a Quine but hey the thought counts

Prime Numbers

STILL PYTHON!!!!!!!!
Size (you know the unit): 87
Code:

for i in range(2,101):
 x=1
 for q in range(2,i):
  if i%q==0:
   x=0
 if x:
  print(i)


For long Prime numbers:

for i in range(2,10001):
 x=1
 for q in range(2,i):
  if i%q==0:
   x=0
 if x:
  print(i)

Leap Years

for i in range(1800,2401,4):
 if i%400:a=0
 if i%100:a=1
 if a:print(i)