65
\$\begingroup\$

Remember the kids game, 'Duck, Duck, Goose'? No? Me neither.

The challenge

  • Print the word 'duck' on individual lines an indeterminate amount of times.
  • Print the word 'goose'.
  • Your program ends.

The rules

  • Attempt to play the game in the fewest bytes.
  • There must be at least one duck.
  • There must be exactly one goose, at the end of the list.
  • There must be exactly one bird on each line. No empty lines.
  • The case of the outputted strings is irrelevant.
  • White-space within a line is fine.
  • Your program must finish.
  • Your program must not consistently produce the same number of ducks.

Have fun!


Please note: This question is not a duplicate of Shortest code to produce non-deterministic output

Reasons include:

  • The association to a childrens' game
  • The defined start and end requirements of the result string. There is no specified output in the other challenge.
  • Answers For the other, non-duplicate challenge are in a single-digit number of bytes. The average for this one is around 30, or there about.
  • By the amount of overlap between this challenge and that one, any code-golf question including the 'random' tag is a duplicate. Should we delete them all?
  • The code answers for this challenge would match the other challenge (in a ridiculously bloated way), but the answers to that challenge would not match this one.
\$\endgroup\$
14
  • 11
    \$\begingroup\$ Could you define indeterminate? Could it mean either zero or one? \$\endgroup\$
    – recursive
    Mar 12, 2018 at 15:51
  • 1
    \$\begingroup\$ Please define how randomly this should be generated. Uniform in range or with exponential decline? \$\endgroup\$
    – hyper-neutrino
    Mar 12, 2018 at 15:52
  • \$\begingroup\$ @recursive Nope, but let's go with a working definition... The program does not consistently present the same number of ducks. \$\endgroup\$
    – AJFaraday
    Mar 12, 2018 at 15:52
  • 3
    \$\begingroup\$ Speaking as a Minnesotan, what if mine prints "duck, duck, gray duck" instead? :) \$\endgroup\$
    – Mike Hill
    Mar 14, 2018 at 19:13
  • 1
    \$\begingroup\$ @jpmc26 I’m sure there are others. You’d have had to play it with others, for a start. \$\endgroup\$
    – AJFaraday
    Mar 15, 2018 at 23:13

125 Answers 125

1 2 3 4
5
1
\$\begingroup\$

Keg, 19 bytes

(~2%1+|duck\
)goose

Explanation

(~2%          Repeat random number in range 0,1
    1+        Increment to range 1,2
      |       Do:
       duck   Push "duck"
           \  and a newline
)             End
goose         Push "goose"

TIO

\$\endgroup\$
1
\$\begingroup\$

Vyxal oH, 12 bytes

℅(‛¦ø,)`go⋎Ǒ

Try it Online!

The H flag (preset stack to 100) is really useful lol

\$\endgroup\$
1
\$\begingroup\$

><> (Fish), 22 bytes

"duck"a>x
ose"r>o<>"go

Try it

\$\endgroup\$
1
  • 1
    \$\begingroup\$ That interpreter it's fascinating to watch! \$\endgroup\$
    – AJFaraday
    Feb 8 at 8:11
1
\$\begingroup\$

Fortran (GFortran), 47 59 bytes

print'(A)',('duck',j=0,mod(i,5)**2),'goose';end

Try it online!   59 bytes

Had to put this code into a subroutine otherwise the loop doesn't run. Some weird compiler stuff going on, probably because i wasn't initialised, to produce randomness.

\$\endgroup\$
1
\$\begingroup\$

Thunno 2 TO, 10 bytes

ɼ{`_*£}`⁾®

Attempt This Online!

Or, 12 bytes flagless:

Tɼ{`_*£}`⁾®£

Attempt This Online!

Explanation

Tɼ{`_*£}`⁾®£  # Full program
T             # Push 10. The T flag implicitly does this.
 ɼ            # Pop it and push a random number from 1 to 10.
  {    }      # Loop that many times:
   `_*        #  Push the compressed string "Duck"
      £       #  And print it with a newline
        `⁾®   # Push the compressed string "Goose"
           £  # And print it. The O flag forces the implicit output.
\$\endgroup\$
1 2 3 4
5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.