Search Results


Friday, April 03, 2020

Fizzbuzz Program

Python 1
for num in range(1, 21):
    if num % 3 == 0 and num % 5 == 0:
        print('FizzBuzz')
    elif num % 3 == 0:
        print('Fizz')
    elif num % 5 == 0:
        print('Buzz')
    else:

        print(num)

Python2
for i in range(1, 21):
    print ("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i) )


Powershell
for ($i = 1; $i -lt 21; $i++) {
  $output = ""

  if ($i % 3 -eq 0) {
    $output += "Fizz"
  }

  if ($i % 5 -eq 0) {
    $output += "Buzz"
  }

  if ($output -eq "") {
    $output = $i
  }  Write-Output $output
}


Bash script
#!/bin/bash

x=1

while [ $x -le 21 ]
do
  if [[ 0 -eq "($x%15)" ]]
  then
    echo "fizz buzz"
  elif [[ 0 -eq "($x%5)" ]]
  then
    echo "buzz"
  elif [[ 0 -eq "($x%3)" ]]
  then
    echo "fizz"
   else
    echo "$x"
   fi   
  x=$(( $x + 1 ))
Done



Javascript
console.log("One Liner");
for (let i = 0i < 21; )
  console.log((++i % 3 ? "" : "fizz") + (i % 5 ? "" : "buzz") || i);
console.log("Simpler");

for (var i = 1i < 21i++) {
  if (i % 15 === 0console.log("FizzBuzz");
  else if (i % 3 === 0console.log("Fizz");
  else if (i % 5 === 0console.log("Buzz");
  else console.log(i);
}



Java
package client;

public class Fizzbuzz {
    public static void main(String[] args) {
        IntStream.range(1, 16)
.mapToObj(i -> {
if (i % 15 == 0)
return "FizzBuzz";
else if (i % 3 == 0)
return "Fizz";
else if (i % 5 == 0)
return "Buzz";
else
return "" + i;
}).forEach(System.out::println);
       }
   }
}

C
#include

int
main ()
{
  int i;

  for (i = 1; i < 21; i++)
    {
      if (i % 15 == 0)
        printf ("FizzBuzz");
      else if (i % 3 == 0)
        printf ("Fizz");
      else if (i % 5 == 0)
        printf ("Buzz");
      else
        printf ("%d", i);
      printf("\n");
    }

  return 0;
}

Go-Lang
package main

import (
    "fmt"
)

func main() {
  for i := 1; i < 21; i++ {
        if i%15 == 0 {
            fmt.Println("FizzBuzz")
        } else if i%3 == 0 {
            fmt.Println("Fizz")
        } else if i%5 == 0 {
            fmt.Println("Buzz")
        } else {
            fmt.Println(i)
        }
    }
}


PL/SQL
set serveroutput on;

declare
    i number := 0;
begin
    for i in 1..21
    loop
        if mod(i, 3) = 0 and mod(i, 5) = 0 then
            dbms_output.put_line('FizzBuzz');
        elsif mod(i, 3) = 0 then
            dbms_output.put_line('Fizz');
        elsif mod(i, 5) = 0 then
            dbms_output.put_line('Buzz');
        else
            dbms_output.put_line(to_char(i));
        end if;
    end loop;
end;
/


Oracle SQL
select rownum i,
       case
       when mod(rownum, 3) = 0 and mod(rownum, 5) = 0 then 'FizzBuzz'
       when mod(rownum, 3) = 0 then 'Fizz'
       when mod(rownum, 5) = 0 then 'Buzz'
       else to_char(rownum)
       end
from dual
connect by level < 21;

The Theory of Constraints

The Theory of Constraints is a methodology for identifying the most critical limiting factor that stands in the way of achieving a goal and then systematically improving that constraint until it is no longer the limiting factor. In manufacturing, the constraint is often referred to as a bottleneck.

The core concept of the Theory of Constraints is 
  • Every production system is composed set of chained events the led to the creation of finished goods or services.
  • The whole system is called Flow, the raw material goes in one end, and finished goods come from the other end.
  • The rate of Output of the Flow is directly proportional to the Output of the weakest link in the Flow. And the weakest link is called a bottleneck.
  • To improve capacity, we just have to improve the bottleneck. 
  • Its everyone's responsibility in the organization to swarm around and fix the bottleneck if it is stuck.
  • Any improvements not done at the bottleneck is just an illusion.


The Five Focusing Steps
The Theory of Constraints provides a specific methodology for identifying and eliminating constraints, referred to as the Five Focusing Steps. It is a cyclical process.

Identify
Identify the current constraint (the single part of the process that limits the rate at which the goal is achieved).

Exploit 
Make quick improvements to the throughput of the constraint using existing resources (i.e. make the most of what you have).

Subordinate 
Review all other activities in the process to ensure that they are aligned with and truly support the needs of the constraint.

Elevate 
If the constraint still exists (i.e. it has not moved), consider what further actions can be taken to eliminate it from being the constraint. Normally, actions are continued at this step until the constraint has been “broken” (until it has moved somewhere else). In some cases, capital investment may be required.

Repeat 
The Five Focusing Steps are a continuous improvement cycle. Therefore, once a constraint is resolved the next constraint should immediately be addressed. This step is a reminder to never become complacent – aggressively improve the current constraint…and then immediately move on to the next constraint.


Although this is created initially for the Manufacturing industry to manage production system, it could really be applied to anything.

The idea is to concentrate the core efforts on most pressing issues facing the organization.