Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@matslina
Last active December 24, 2015 20:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matslina/6859231 to your computer and use it in GitHub Desktop.
Save matslina/6859231 to your computer and use it in GitHub Desktop.
#define EOF char* /* !\
cat >>/dev/null <<EOF
set K {
[
This is a 4-language polyglot; it is valid brainfuck, C, Bash and
Tcl. The program prints a Spotify banner when run.
2013-10-06 - Mats Linander - matslina at gmail dot com
]*/
EOF
K="\
++++[- \
>++++++++<]>.++++.. \
....[--<+++++>]<++.+[---> \
+<]>+.......................+ \
+++..[--<+++++>]<++.+[--->+<]>+.. \
...++++..[--<+++++>]<++.+[--->+<]>+.. \
++++......[--<+++++>]<++.--[--------->+ \
<]>.-[-<++++>]<..----..[->+++<]>-..[----- \
<++>]<--..[-->+++++<]>++.+[---<+>]<+....... \
...............++++..----.-[->++++<]>.[----<+>] \
<+....-[->+++<]>-.+++..--[---<++++>]<.-[--->+<]>- \
----..----..[-<+++>]<-..[----->++<]>--..[--<+++++>] \
<++.--[--------->+<]>.-[-<++++>]<..----.[-->+++<]>-.+ \
[---<++>]<..-[->+++<]>-.+++..--[---<++++>]<.[---->+<]>+ \
.++++......[--<+++++>]<++.+[--->+<]>+...++++......[--<+ \
++++>]<++.+[--->+<]>+.++++......[--<+++++>]<++.+[--->+<]> \
+...++++..[--<+++++>]<++.+[--->+<]>+.++++..----.[--<+++>]<- \
.+[--->++<]>..-[-<+++>]<-.+++..--[--->++++<]>.-[---<+>]<---- \
-..[-->+++++<]>++.+[---<+>]<+...++++..[-->+++++<]>++.--[------- \
--<+>]<.[->+++++++ ++<]>++.--[-----<++>]<..... \
.[-->+++++<]>+ +.+[---<+>]<+..++++..- \
---..[->++ +<]>-..[-----<++>]< \
--..[-->++ +++<]>++.+[---< \
+>]<+.+++ +..----..[->++ \
+<]>-..[- ----<++>]<-- \
..[-->++++ +<]>++..+++ \
.[-----<++> ]<--..----..[->+++< ]>-.--[-- \
-<++++>]<.[- --->+<]>+..++++..----.-[-<+++ +>]<.-[- \
-->+<]>-----....[--<+++++>]<++.+[--->+<]>+.....++ ++..----. \
-[-<++++>]<.[---->+<]>+..++++..----.-[-<++++>]<.---[ --------- \
-->+<]>-.[-<+++>]<++.-[->+++<]>-.+++....[-----<++>]<--. .[-->++++ \
+<]>++.+[---<+>]<+.++++..----.[-->+++<]>-.+[---<++>]<..+ +++..----. \
-[->++++<]>.-[---<+>] <-----..----.[-->++ +<]>-.+[--- \
<++>]<..++++..--- -.-[->++++<]>.[----<+>]<+.++ \
++..----.-[->++ ++<]>.[----<+>]<+....+++ \
+..----.-[->++ ++<]>.-[---<+>]<----- \
..----..[->+++ <]>-.--[---<++++>]<. \
[---->+<]>+... .++++..----.-[-<++ \
++>]<.[---->+< ]>+..++++..----.-[ -<++++>]<.---[--- \
-------->+<]>-.-[-<++++>]<..[-->+++++<]>++.+ [---<+>]<+...+++ \
+..----.-[->++++<]>.-[---<+>]<-----..----.-[->+ +++<]>.[----<+> \
]<+..++++..----.-[->++++<]>.-[---<+>]<-----..---- .-[->++++<]>.[- \
---<+>]<+..++++..----.-[->++++<]>.[----<+>]<+.++++. .----.-[->++++< \
]>.-[---<+>]<-----..[-->+++++<]>++.+[---<+>]<+.++++.. ----.-[->++++<]> \
.-[---<+>]<-----..---- .-[->++++<]>.[----<+>]<+......++++ \
..----.-[->++++< ]>.[----<+>]<+..++++..----.-[ \
->++++<]>.---[- ----------<+>]<-.[->++++++ \
+++<]>++.--[-- ---<++>]<......----..-[ \
->++++<]>.-[- -- <+>]<-----.......--- \
-..-[->++++<]> .[----<+++>]<-.--[- ---->++<]>......-- \
--..-[-<++++>]<.[---->+<]>+.-[-<+++>]<-.- -[----->++<]>.... \
----..-[-<++++>]<.-[--->+<]>-----..----.-[ -<++++>]<.-[---> \
+<]>-----..----.-[-<++++>]<.[---->+<]>+...... -[-<+++>]<-.--[- \
---->++<]>.......----.-[-<++++>]<.---[-------- --->+<]>-.[-<++ \
+>]<++.-[->+++<]>-.+++......-[--<+>]<.+[--->++<]>.++++..----..[- \
<+++>]<-....-[-->+<]>.+[---<++>]<..-[->+++<]>-.+++......-[--< \
+>]<.+[--->++<]>...-[-<+++>]<-.+++....-[-->+<]>.+[---<++>]<. \
-[->+++<]>-.+++..--[---<++++>]<.[---->+++<]>-.+++..--[---< \
++++>]<.[---->+<]>+.......-[-<+++>]<-.+++....[----->++<] \
>--..----.-[-<++++>]<.---[----------->+<]>-.[-<+++>]<++. \
.........++++..----.-[->++++<]>.[----<+>]<+........... \
............................++++..[-->+++++<]>++.+[- \
--<+>]<+...++++..----.-[->++++<]>.---[-----------< \
+>]<-.[->+++<]>++..........++++..----.-[-<++++>] \
<.[---->+<]>+............................... \
........-[-<+++>]<-.--[----->++<]>......-- \
--..-[-<++++>]<.---[----------->+<]>-.[- \
<+++>]<++..........-[->+++<]>-.+++..-- \
[---<++++>]<.[---->+<]>+.......... \
.............................. \
-[-<+++>]<-.+++......-[--> \
+<]>.+[----<+>]<--..>";
#if 0 /*[
O0=($(echo "$K"|sed -e"s/\(.\)/\\1 /g"));OO=($(for((i=0;i<65535;i++))
do echo "0";done));Oo=0;oo="";oO=0;o0=0;while [ $oO -lt ${#O0[@]} ];do
case ${O0[$oO]} in ">")o0=$((o0+1));;"<")o0=$((o0-1));;"+")OO[$o0]=$((
(${OO[$o0]}+1)%0x100));;"-")OO[$o0]=$(((${OO[$o0]}+0377)%0x100));;".")
echo -ne "\0$(((${OO[$o0]}/64)%8))""$(((${OO[o0]}/8)%8))$((${OO[o0]}%8
))";;",")if ((${#oo}==0)); then oo=$(cat);fi;if ((${#oo}>0)); then OO[
$o0]=$(printf "%d" "'${oo:0:1}");oo=${oo:1};fi;;"[")if ((${OO[$o0]}==0
));then c=1;while (($c>0));do oO=$(($oO+1));if [ ${O0[$oO]} == \[ ] ;
then c=$((c+1));fi;if [ ${O0[$oO]} == \] ]; then ((c-- ));fi;done;else
O0O[$Oo]=$oO;((Oo++)); fi;;"]")((Oo--));if ((${OO[$o0]})); then oO=$((
${O0O[$Oo]}-1));fi;;esac;((oO++));done;
cat >>/dev/null <<EoF
*/
#else
#define _K_(___,_K,__)(K[_KK]^(___))?_K_^_K_:_K _K_ __;
_K_,_KK,__K,____,__[4>>002<<020]; _(__){__K=____?__K:__;____=__;while(
__K){__K+=*(__*__*__+_KK+K)-0133?22^_KK[K+__]^'K'?'.'^'u'^'[':-(__[_KK
+K]&1):__*__;_KK+=__;_(__);}}___(){while(K[++_KK]){ _K_('v'^']',__[
,]++)_K_(055|___==___,__[,]--)_K_('K'^'u',,++)_K_('w'^'K',--,)_K_('_'^
4,__[,]?_(_KK[K]&1>>1):_(_KK[K]&1))_K_('v'^'+',__[,]?_((_KK[K]&2)-(_KK
[K]&1)):_(0))K[_KK]-46?_(__[_K_]&1>>1):putchar(__[_K_]);if(_KK[K]^(1<<
1^'.'))_(0);else{__[_K_]=getchar();}}}main(){--_KK;___();}
#endif
#define EoF
#if 0
]}
#[
fconfigure stdout -encoding binary;fconfigure stdin -encoding binary;set __ 0
set _ 0;set _1 {0};;for {set ___ 0} {$___<0xffff} {incr ___} {lappend _1 0}
lappend _1_ 0;;while {$_ < [string length $K]} {switch -exact -- \
[string index $K $_] {{>} {incr __} {<} {set __ [expr $__-1]} {,}
{set __1 [read stdin 1]; if {[string length $__1]==1} {lset _1 $__ [scan $__1 \
%c]}} {.} {puts -nonewline stdout [format %c [lindex $_1 $__]]} {[} {
if {[lindex $_1 $__] == 0} {set ___ 1; while {$___ != 0} {incr _;
set __1 [string index $K $_];if {[string equal $__1 {[} ]} {incr ___;} \
elseif {[string equal $__1 {]}]} {set ___ [expr $___-1]}}} else {
lappend _1_ [expr $_ - 1]}} {]} {if {[lindex $_1 $__] != 0} {
set _ [lindex $_1_ end]};set _1_ [lrange $_1_ 0 end-1]} {+} {
lset _1 $__ [expr ([lindex $_1 $__] + 1)%256]} {-} {lset _1 $__ [expr \
([lindex $_1 $__] - 1)%256]} default {}}; incr _}
exit
]
#endif
EoF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment