Skip to content

Instantly share code, notes, and snippets.

@jftuga
Last active October 25, 2024 01:58
Show Gist options
  • Select an option

  • Save jftuga/2a21954af56af19f89b0c627384b53da to your computer and use it in GitHub Desktop.

Select an option

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 a,char*b[]){printf("%d\n",n)&&--n&&main(n,NULL);}
// run: go run countdown.go
package main;func main(){n(10)};func n(i int){println(i);if i>1{n(i-1)}}
// node
n=10;main=_=>(console.log(n),n>0&&n--&&main());main()
// or...
n=10;main=_=>{console.log(n);n>0&&n--&&main()};main()
import sys # run: python3 countdown.py 10
def main(n:int): print(n) or n-1 and main(n-1)
main(int(sys.argv[1]))
fn main(){let _=(10..=1).rev().map(|n|println!("{}",n)).collect::<Vec<_>>();}
# run ./countdown.sh 10
echo $1&&(($1-1))&&$0 $(($1-1))
pub fn main()void{if(@as(u8,10)>0)_=print("{}\n",.{10})||(main()catch{});}
package main;var n=10;func main(){print(n,"\n");if n>0{n-=1;main()}}
# this is a list comprehension, which interally does use a for loop
# run: python3 countdown2.py
_=[print(n)for n in range(10,0,-1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment