Last active
August 26, 2021 15:02
-
-
Save DeclanHoare/7e68ba108b0c8a7f3cb6c4b70d2d957a to your computer and use it in GitHub Desktop.
A 99 bottles polyglot in 4 languages (C, C++, C#, HTML+JS) which only states the logic and text once
This file contains 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
/* | |
<script type="text/javascript"> | |
var ourtext = ""; | |
function printf(format, number) | |
{ | |
ourtext += format.replace("%d", number).replace("\n", "<br />"); | |
} | |
function display() | |
{ | |
document.body.innerHTML = ourtext; | |
} | |
</script> | |
<body onload="display()"> | |
<!-- | |
*/ | |
#if __LINE__ | |
#if __cplusplus | |
extern "C" int printf(const char* format, ...); | |
#else | |
extern int printf(const char* format, ...); | |
#endif | |
int main(int argc, char** argv) | |
#else | |
public static class Hello | |
{ | |
private static void printf(string format, int number = 0) | |
{ | |
System.Console.Write(format.Replace("%d", number.ToString())); | |
} | |
public static void Main(string[] args) | |
#endif | |
{ | |
int i; | |
/*--><script type="text/javascript"> | |
var i; | |
//*/ | |
i = 99; | |
while (1 == 1) | |
{ | |
printf("%d bottles of beer on the wall,\n", i); | |
printf("%d bottles of beer,\n", i); | |
printf("If one of those bottles should happen to fall\n"); | |
if (--i == 1) | |
break; | |
printf("there'd be %d bottles of beer on the wall.\n", i); | |
} | |
printf("there'd be 1 bottle of beer on the wall.\n"); | |
printf("1 bottle of beer on the wall,\n"); | |
printf("1 bottle of beer,\n"); | |
printf("If that one bottle should happen to fall\n"); | |
printf("there'd be no more bottles of beer on the wall.\n"); | |
//</script> | |
//<!-- | |
#if __LINE__ | |
return 0; | |
#endif | |
} | |
#if !__LINE__ | |
} | |
#endif | |
/* | |
--> | |
</body> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment