Skip to content

Instantly share code, notes, and snippets.

@jftuga
Last active April 21, 2023 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jftuga/2a21954af56af19f89b0c627384b53da to your computer and use it in GitHub Desktop.
Save jftuga/2a21954af56af19f89b0c627384b53da to your computer and use it in GitHub Desktop.
Code Golf

Code Golf Challenge

  • Write a program that counts down from 10 (and can either end at 0|1) -- your choice
  • Prints one number per line
  • Can optionally accept a command-line argument
  • No looping constructs are allowed, such a for and while
  • Make it as short as possible, but still readable
  • Please reply with your own solutions, include the programming language
    • Include instructions on how to compile && run
#include <stdio.h> // compile & run: gcc -Wall countdown.c -o countdown && ./countdown
int n = 10; int main(int argc, char *argv[]) { printf("%d\n", n) && --n && main(n, NULL); }
import sys # run: python3 countdown.py 10
def main(n:int): sys.stdout.write(f"{n}\n") and n-1 and main(n-1)
main(int(sys.argv[1]))
# run ./countdown.sh 10
echo $1 && (($1-1)) && $0 $(($1-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment