Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

colinwil

macrumors 6502
Original poster
Nov 15, 2010
299
169
Reading, UK
Back in 1988, a couple of guys wrote a Christmas program in C which won the top prize in the International Obfuscated C Code Contest.



So of course, I had to translate it to Swift 4. When you've got a free moment, paste it into a Swift playground and see what you get



Merry Christmas!

//
// Xmas.swift
//
// Original C version:
// Copyright (c) 1988, Landon Curt Noll & Larry Bassel.
// All Rights Reserved. Permission for personal, educational or non-profit use
// is granted provided this this copyright and notice are included in its entirety
// and remains unaltered. All other uses must receive prior permission in
// writing from both Landon Curt Noll and Larry Bassel.
//
// Swift 4 version Copyright © 2018 Colin Wilson. All rights reserved.
//


import Foundation

@discardableResult func t_ (_ t: Int, _ x: Int, _ a: UnsafePointer<Int8>, _ s: inout String) -> Int {
if 1<t { if t<3 { t_(-79,-13,a+t_(-87,1-x,t_(-86,0,a+1, &s)+a, &s), &s
); }; if t<x {t_(t+1,x,a, &s)}; return t_(-94,-27+t,a, &s) != 0
&& t==2 ? (x<13 ? t_(2,x+1, "%s %d %d\r", &s) : 9) : 16 }
else if t<0 { if t < -72 {return t_(x,t,"@n'+,#'/*{}w+/w#cdnr/+," +
"{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'" +
"d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'" +
"/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){nl]!/n{n#'; r{#w'r nc{nl]" +
"'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; " +
":{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'" +
"/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/", &s)} else
if t < -50 {if x == a [0] {s += String (Character (UnicodeScalar (Int (
a[31]))!)); return Int (a[31])} else {return t_(-65,x,a+1,
&s)}} else {return t_((a [0] == 47 ? 1 : 0)+t,x,a+1, &s)}}
else if 0<t {return t_(2,2,"%s", &s)} else { return a [0] == 47 ? 1 :
t_(0,t_(-61,Int (a[0]),"!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\ruwloca-O;m " +
".vpbks,fxntdCeghiry", &s),a+1, &s) != 0 ? 1 : 0}
}

var str = ""
t_ (1, 10000, "", &str)
print (str)
 
As someone who hasn't programmed since the 1980's on a C-64, I cannot even begin to comprehend how this worked. Mind Blow...

On the first day of Christmas my true love gave to me

a partridge in a pear tree.



On the second day of Christmas my true love gave to me

two turtle doves

and a partridge in a pear tree.



On the third day of Christmas my true love gave to me

three french hens, two turtle doves

and a partridge in a pear tree.



On the fourth day of Christmas my true love gave to me

four calling birds, three french hens, two turtle doves

and a partridge in a pear tree.



On the fifth day of Christmas my true love gave to me

five gold rings;

four calling birds, three french hens, two turtle doves

and a partridge in a pear tree.



On the sixth day of Christmas my true love gave to me

six geese a-laying, five gold rings;

four calling birds, three french hens, two turtle doves

and a partridge in a pear tree.



On the seventh day of Christmas my true love gave to me

seven swans a-swimming,

six geese a-laying, five gold rings;

four calling birds, three french hens, two turtle doves

and a partridge in a pear tree.



On the eigth day of Christmas my true love gave to me

eight maids a-milking, seven swans a-swimming,

six geese a-laying, five gold rings;

four calling birds, three french hens, two turtle doves

and a partridge in a pear tree.



On the ninth day of Christmas my true love gave to me

nine ladies dancing, eight maids a-milking, seven swans a-swimming,

six geese a-laying, five gold rings;

four calling birds, three french hens, two turtle doves

and a partridge in a pear tree.



On the tenth day of Christmas my true love gave to me

ten lords a-leaping,

nine ladies dancing, eight maids a-milking, seven swans a-swimming,

six geese a-laying, five gold rings;

four calling birds, three french hens, two turtle doves

and a partridge in a pear tree.



On the eleventh day of Christmas my true love gave to me

eleven pipers piping, ten lords a-leaping,

nine ladies dancing, eight maids a-milking, seven swans a-swimming,

six geese a-laying, five gold rings;

four calling birds, three french hens, two turtle doves

and a partridge in a pear tree.



On the twelfth day of Christmas my true love gave to me

twelve drummers drumming, eleven pipers piping, ten lords a-leaping,

nine ladies dancing, eight maids a-milking, seven swans a-swimming,

six geese a-laying, five gold rings;

four calling birds, three french hens, two turtle doves

and a partridge in a pear tree.​
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.