Code Golf 2 | FizzBuzz Problem

Code Golf Hello every one. Welcome to the second episode of Code Golf In this video we are going to solve the Fizzbuzz problem Before we start with the Fizzbuzz problem Shout out to Emad Ismael for breaking my score record on divisors I scored 76 and he came up with an awesome short solution he finished the problem in just 64 characters I really love this kind of well spirited competition where we are trying to beat each other’s score by learning new things about our favorite programming language So today, if you beat my Fizzbuzz problem score Go ahead to twitter and tweet to me @pylenin I broke your Fizzbuzz score with __ characters and you fill in the blank with the number of characters that you have So let’s get started Now we already know what Fizzbuzz problem is. If you haven’t watched my video on Fizzbuzz problem click on the i link and watch my video and then come back here so we all can compete So let’s just write a basic code to solve the Fizz buzz problem Let’s not worry about how short our code is Let’s just write a simple code So here I can say You can actually put if clause and print in the same line However, it reduces readability Readability is not the game We just have to write the code in the shortest way possible Let’s reduce the code even further Here you can see I have multiple if elif else statements, right? There is a shorter way in which we can write multiple if-else statements so that our characters will be less but the functionality will still be the same I will show you how we can do it Here you can see I have x=10 and y=20 Let’s do a small experiment Here I can write a normal if-else clause here if x>y print(1) else print(0)


  • hey i can pay $5 per hour for live tutoring python web scraping etc are you interested

  • Awesome 👌

  • the divisors with for loop (64)


    for i in l:print(*[j for j in l if i%j==0])

  • @pylenin i broke your FizzBuzz score on Code Golf with 66 characters


    while i<101:print((i%3==0)*"Fizz" + (i%5==0)*"Buzz" or i);i+=1

  • Instead of using ==0 use <1
    This saves 1 character

    Divisors is now 63 characters
    while i<101:print(*[y for y in range(1,i+1) if i%y<1]);i+=1

    FizzBuzz is now 62 characters
    for i in range(1,101):print((i%3<1)*'Fizz'+(i%5<1)*'Buzz'or i)

  • I found your channel on reddit, and have been loving your videos. The enthusiasm you have for the language and teaching it to others is inspiring and motivational. It is also very informal, with cuts of your life interspersed throughout, and that adds to the accessibility.

    Please keep making videos!

  • Shirsendu Mazumdar

    Awesome !!
    Lenin , myself Shirsendu .Recently I did attend an interview with a company , where I faced some coding challenge and failed …I am posting those coding question here below ….If you find some free time kindly try to solve probs ..and share your solutions

    1..The number, 719, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

    There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

    Given an input number N, return how many circular primes are there below N?

    Constraints: N <= 1,000,000

    Runtime limit: 10 sec

    Input: N (integer)

    Output: Number of circular primes <= N (integer)


    Input: 10

    Output: 4

    Explanation: There are 4 circular primes below 10: 2, 3, 5, 7

    Input: 100

    Output: 13

    2..Given an array of numbers, arrange them in a way that yields the largest value. For example, if the given numbers are {54, 546, 548, 60}, the arrangement 6054854654 gives the largest value.

    Input: Array of Integers where each Integer >=1 and is <=1000

    Sample Input – (First value is the length of array)

    4(Length of array)





    Sample Output – 6054854654 is a collection of N strings ( There can be multiple occurrences of a particular string ). Each string's length is no more than 20 characters. There are also Q queries. For each query, you are given a string, and you need to find out how many times this string matches exactly in the given collection of N strings.

    Input Format

    The first line contains N, the number of strings.

    The next N lines each contain a string.

    The N + 2nd line contains , the number of queries.

    The following Q lines each contain a query string.


    1 <= N <= 1000

    1 <= Q <= 1000

    1 <= length of any string <= 20

    Thank you for your co-operation in advance …………………………….

  • you could easily reduce the 3 spaces between 'and+, +and(, )and or Lol

Leave a Reply

Your email address will not be published. Required fields are marked *