top | item 35694737

(no title)

amrb | 2 years ago

Can some one test fizzbuzz, sounds silly tho a lot of models fail on the combination check in my tests.

discuss

order

krasin|2 years ago

Q> Write a FizzBuzz problem in COBOL

A> Sure, here is the FizzBuzz problem in COBOL:

    IDENTIFICATION DIVISION.
    PROGRAM-ID. FIZZBUZZ.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 COUNT PIC 9(02).
    01 MESSAGE PIC X(08).
    01 BLANK PIC X(01) VALUE SPACES.
    PROCEDURE DIVISION.
    INITIALIZE.
    MOVE 1 TO COUNT.
    PERFORM UNTIL COUNT > 100
      EVALUATE COUNT
        WHEN 3
          MOVE "Fizz" TO MESSAGE
        WHEN 5
          MOVE "Buzz" TO MESSAGE
        WHEN 3 AND 5
          MOVE "FizzBuzz" TO MESSAGE
        WHEN OTHER
          MOVE COUNT TO MESSAGE
      END-EVALUATE
      DISPLAY MESSAGE
      ADD 1 TO COUNT
    END-PERFORM.
    GOBACK.
This program prints the numbers from 1 to 100. However, for multiples of 3, it prints "Fizz" instead of the number. For multiples of 5, it prints "Buzz" instead of the number. And for multiples of both 3 and 5, it prints "FizzBuzz" instead of the number.

Here is an example of the output of the program:

    1
    2
    Fizz
    4
    Buzz
    Fizz
    7
    8
    Fizz
    Buzz
    11
    Fizz
    13
    14
    FizzBuzz
    16
    17
    Fizz
    19
    Buzz
Disclosures:

1. I work for Google, but not on Bard.

2. I don't know COBOL. Would be good if someone can check if the code is legit. I get a feel that it checks for the numbers to match (3, 5), not be divisible by 3 and 5.

jiggawatts|2 years ago

It's obviously wrong, it's not using the modulo function anywhere or any such construct. It'll print text only for '3' and '5', and then numbers from then on.

By the way, GPT 4 when asked to critique this listing immediately found the problem, and produced a corrected version as a bonus.

Bard feels like GPT 2 to me. Even GPT 3.5 can solve COBOL FizzBuzz correctly.

PS: Just to check that GPT 4 is understanding the problem and not just regurgitating something it saw, I asked it to solve the problem in different ways, such as unrolling the loop or avoiding the use of the MOD function. It can do that too.