In how many languages can you count to 10?
In how many languages can you count to 10?
Ok, Lemmy, let's play a game!
Post how many languages in which you can count to ten, including your native language. If you like, provide which languages. I'm going to make a guess; after you've replied, come back and open the spoiler. If I'm right: upvote; if I'm wrong: downvote!
Bonus question: do you ever do your counting in a non-native language, just to make it more interesting?
1. Python
for i in range(11): print(i)2. R
for (i in 0:10) { print(i) }3. C/C++
#include <iostream> int main() { for (int i = 0; i <= 10; ++i) { std::cout << i << std::endl; } return 0; }4. Java
public class CountToTen { public static void main(String[] args) { for (int i = 0; i <= 10; i++) { System.out.println(i); } } }5. Lua
for i = 0, 10 do print(i) end6. Bash (Shell Script)
for i in $(seq 0 10); do echo $i done7. Batch (Windows Command Script)
@echo off for /l %%i in (0,1,10) do ( echo %%i )8. Go
package main import "fmt" func main() { for i := 0; i <= 10; i++ { fmt.Println(i) } }9. Rust
fn main() { for i in 0..=10 { // 0..=10 includes 10 println!("{}", i); } }10. Zig
const std = @import("std"); pub fn main() !void { var i: i32 = 0; while (i <= 10) { std.debug.print("{}\n", .{i}); i += 1; } }11. Scala
for (i <- 0 to 10) { println(i) }12. Fortran
program count_to_ten implicit none integer :: i do i = 0, 10 print *, i end do end program count_to_ten13. Haskell
main :: IO () main = mapM_ print [0..10]14. Julia
for i in 0:10 println(i) endIf you didn't cheat that's actually pretty impressive.
It is astonishingly easy to get basically any LLM to output a simple iteration from one to ten function in all of those languages, and more.
Here's Assembly:
newline db 0xA ; Newline character section .bss number resb 1 ; Reserve a byte for the number section .text global _start _start: mov ecx, 1 ; Start with 1 mov edx, 10 ; End with 10 loop_start: cmp ecx, edx ; Compare ecx with edx jg loop_end ; If ecx > edx, jump to loop_end ; Convert number to ASCII add ecx, '0' ; Convert number to ASCII mov [number], ecx ; Store the ASCII value in number ; Print the number mov eax, 4 ; sys_write system call mov ebx, 1 ; File descriptor 1 is stdout mov ecx, number ; Pointer to the number mov edx, 1 ; Number of bytes to write int 0x80 ; Call kernel ; Print newline mov eax, 4 ; sys_write system call mov ebx, 1 ; File descriptor 1 is stdout mov ecx, newline ; Pointer to the newline character mov edx, 1 ; Number of bytes to write int 0x80 ; Call kernel sub ecx, '0' ; Convert ASCII back to number inc ecx ; Increment the number jmp loop_start ; Jump back to the start of the loop loop_end: ; Exit the program mov eax, 1 ; sys_exit system call xor ebx, ebx ; Exit code 0 int 0x80 ; Call kernelHere's FORTRAN
program iterate_from_one_to_ten implicit none integer :: i ! Loop from 1 to 10 do i = 1, 10 print *, i end do end program iterate_from_one_to_tenHere's COBOL
PROGRAM-ID. IterateFromOneToTen. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-Counter PIC 9(2) VALUE 1. PROCEDURE DIVISION. PERFORM VARYING WS-Counter FROM 1 BY 1 UNTIL WS-Counter > 10 DISPLAY WS-Counter END-PERFORM. STOP RUN.Yes I cheated. To be fair, I used each of those languages at one point and knew how to do it but was to lazy to look it up again.
Edit: except Fortran
Nice. Surely you could manage Lisp (or Scheme)?
God. Haskell's monads give me nightmares.
I might be missing something, but don't most of these count from 0 to 10, not 1 to 10 as was requested?
Yes, that was on purpose
class CountToTenis the perfect example of why I dislike Java.