- 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
forandwhile - 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
Last active
October 25, 2024 01:58
-
-
Save jftuga/2a21954af56af19f89b0c627384b53da to your computer and use it in GitHub Desktop.
Code Golf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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);} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // run: go run countdown.go | |
| package main;func main(){n(10)};func n(i int){println(i);if i>1{n(i-1)}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // node | |
| n=10;main=_=>(console.log(n),n>0&&n--&&main());main() | |
| // or... | |
| n=10;main=_=>{console.log(n);n>0&&n--&&main()};main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main(){let _=(10..=1).rev().map(|n|println!("{}",n)).collect::<Vec<_>>();} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # run ./countdown.sh 10 | |
| echo $1&&(($1-1))&&$0 $(($1-1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub fn main()void{if(@as(u8,10)>0)_=print("{}\n",.{10})||(main()catch{});} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main;var n=10;func main(){print(n,"\n");if n>0{n-=1;main()}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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