#carolsincode are small pseudo-programs which contain a Christmas song. Some examples display the lyrics while others use the program's control structures to define the song.
Here are five examples in C, CSS and JavaScript. Can you do better? ;-)
var kings=new Array(3); for (x in kings) { kings[x].origin='orient'; kings[x].bearingGift=true; kings[x].travelled='afar'; }
main() { int a; for (a=1;a<5;a++) printf("Noel, "); printf("Born is the King of Israel."); }
#rudolf .nose { color: red; background: url('very_shiny.jpg'); }
while ( shepherds.watch() == 'flocks' && date.getHours() in night ) { lord.angel--; glory.shone_around(); }
for ( c=1, c<=4, c++) { noel() }; king = new Object(); king.kingdom = 'Israel';
The Rudolf one is pretty funny...
ReplyDeleteGreat idea :) It inspired me to do some of my own:
ReplyDeletehttp://www.weedoorsbanging.com/archives/carols-in-code.html
for(i=0;i++<12;)alert("On day "+i+" of xmas: "+"drummers|pipers|lords|ladies|maids|swans|geese|rings|birds|hens|doves|partridge".split("|").map(function(x,n){return 12-n+" "+x}).slice(-i))
ReplyDeletebells.jingle(); bells.jingle(); while( all > 0 ) { way[all--].jingle(); } sleigh.horses=1; sleigh.ride();
ReplyDeletedo {sleigh_bells.ring();} while (you.listening==true); for (snow in lane) {snow.glistening=true}; winter.wonderland='walking';
#!/usr/bin/env python
ReplyDelete# -*- coding: utf-8 -*-
import sys
data = [
[ 2, 4, 2, 2, 8, 2, 8, 2, 8, 2, 2, 4, 2 ],
[ 2, 4, 2, 2, 8, 2, 8, 2, 8, 2, 2, 4, 2 ],
[ 2, 4, 2, 2, 2, 4, 2, 2, 2, 4, 2, 2, 2, 4, 2, 2, 2, 4, 2 ],
[ 2, 4, 2, 2, 2, 4, 2, 2, 2, 4, 2, 2, 2, 4, 2, 2, 2, 4, 2 ],
[ 8, 2, 8, 2, 8, 2, 8, 2, 8 ],
[ 8, 2, 8, 2, 8, 2, 8, 2, 8 ],
[ 2, 4, 2, 2, 2, 4, 2, 2, 2, 8, 2, 11, 2 ],
[ 2, 4, 2, 2, 2, 4, 2, 2, 2, 8, 2, 11, 2 ],
[ 0 ],
[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