This post has been edited by Sheph: 22 December 2011 - 12:32 AM
39 Replies - 14715 Views - Last Post: 15 January 2013 - 06:44 AM
#16
Re: Challenge: 12 Days of Christmas
Posted 21 December 2011 - 11:24 PM
#17
Re: Challenge: 12 Days of Christmas
Posted 22 December 2011 - 10:07 AM
To check you could write your a small application that does it.
In Nemerle:
def CountNonWhiteSpace = (s:string) => s.Count(c => !Char.IsWhiteSpace( c ));
This post has been edited by AdamSpeight2008: 22 December 2011 - 10:31 AM
#18
Re: Challenge: 12 Days of Christmas
Posted 22 December 2011 - 10:28 AM
This post has been edited by blackcompe: 27 December 2011 - 03:13 AM
#19
Re: Challenge: 12 Days of Christmas
Posted 22 December 2011 - 07:04 PM
include masm32rt.inc
ConsolePrint equ print
.data
szNewLine BYTE 13, 10, 0
szA BYTE "A ", 0
szAnd BYTE "And a ", 0
szTop BYTE "On the ", 0
szTop2 BYTE " day of Christmas,", 13, 10
BYTE "my true love gave to me...", 13, 10, 0
szFirst BYTE "first", 0
szSecond BYTE "second", 0
szThird BYTE "third", 0
szFourth BYTE "fourth", 0
szFifth BYTE "fifth", 0
szSixth BYTE "sixth", 0
szSeventh BYTE "seventh", 0
szEighth BYTE "eighth", 0
szNinth BYTE "nineth", 0
szTenth BYTE "tenth", 0
szEleventh BYTE "eleventh", 0
szTwelfth BYTE "twelfth", 0
sz1 BYTE "partridge in a pear tree", 13, 10, 0
sz2 BYTE "Two turtle doves,", 13, 10, 0
sz3 BYTE "Three French hens,", 13, 10, 0
sz4 BYTE "Four calling birds,", 13, 10, 0
sz5 BYTE "Five golden rings,", 13, 10, 0
sz6 BYTE "Six geese a-laying,", 13, 10, 0
sz7 BYTE "Seven swans a-swimming,", 13, 10, 0
sz8 BYTE "Eight maids a-milking,", 13, 10, 0
sz9 BYTE "Nine ladies dancing,", 13, 10, 0
sz10 BYTE "Ten lords a-leaping,", 13, 10, 0
sz11 BYTE "Eleven pipers piping,", 13, 10, 0
sz12 BYTE "Twelve drummers drumming,", 13, 10, 0
TOTALSIZE equ ($ - szNewLine)
NUMBERS DWORD szFirst
DWORD szSecond
DWORD szThird
DWORD szFourth
DWORD szFifth
DWORD szSixth
DWORD szSeventh
DWORD szEighth
DWORD szNinth
DWORD szTenth
DWORD szEleventh
DWORD szTwelfth
THINGS DWORD sz1
DWORD sz2
DWORD sz3
DWORD sz4
DWORD sz5
DWORD sz6
DWORD sz7
DWORD sz8
DWORD sz9
DWORD sz10
DWORD sz11
DWORD sz12
.code
Align 4
@12DaysOfXMas:
enter 12, 0
invoke GetProcessHeap
mov dword ptr [ebp -4], eax
invoke HeapAlloc, eax, HEAP_ZERO_MEMORY, TOTALSIZE
mov edi, eax
lea esi, NUMBERS
lea ebx, THINGS
mov dword ptr [ebp - 12], 0
NextVerse:
cmp dword ptr [ebp - 12], 11
ja Done
mov ecx, dword ptr [ebp - 12]
test ecx, ecx
jnz NotFirstVerse
invoke szMultiCat, 6, edi, offset szTop, dword ptr[esi + 4 * ecx], offset szTop2, offset szA, dword ptr[ebx + 4 * ecx], offset szNewLine
ConsolePrint edi
mov byte ptr [edi], 0
jmp IDunno2
NotFirstVerse:
invoke szMultiCat, 3, edi, offset szTop, dword ptr[esi + 4 * ecx], offset szTop2
mov ecx, dword ptr [ebp - 12]
mov dword ptr [ebp - 8], ecx
@@:
mov edx, dword ptr [ebp - 8]
test edx, edx
jnz NotPartridge
invoke szMultiCat, 2, edi, offset szAnd, dword ptr [ebx + 4 * edx]
jmp Next2
NotPartridge:
invoke szCatStr, edi, dword ptr [ebx + 4 * edx]
Next2:
dec dword ptr [ebp - 8]
jns @B
ConsolePrint edi
mov byte ptr [edi], 0
IDunno2:
inc dword ptr [ebp - 12]
invoke szCatStr, edi, offset szNewLine
jmp NextVerse
Done:
invoke HeapFree, dword ptr[ebp -4], 0, edi
inkey
leave
invoke ExitProcess, 0
end @12DaysOfXMas
#20
Re: Challenge: 12 Days of Christmas
Posted 22 December 2011 - 07:45 PM
Notepad text file is 644 bytes as well. So no different encoding, but always good to check.
This post has been edited by Sheph: 22 December 2011 - 07:47 PM
#21
Re: Challenge: 12 Days of Christmas
Posted 23 December 2011 - 10:29 PM
This post has been edited by blackcompe: 23 December 2011 - 10:41 PM
#22
Re: Challenge: 12 Days of Christmas
Posted 26 December 2011 - 07:38 PM
public class mainClass {
public static void main(String[] argv){
String[] days = {"first","second","third","fourth","fifth","sixth","seventh","eighth","nineth","tenth","eleventh","twelveth"};
String[] gifts = {"a partridge in a pear tree","Two turtle doves","Three french hens","Four calling birds","Five golden rings","Six geese-a-laying","Seven swans-a-swimming","Eight maids-a-milking","Nine ladies dancing","Ten lords-a-leaping","Eleven pipers piping","Twelve drummers drumming"};
for(int i=0;i<days.length;i++){
System.out.print("\nFor the " + days[i] + " day of christmas, my true love gave to me:\n");
for(int j=i;j>-1;j--){
if(i>0 && j==0) System.out.print("and ");
System.out.println(gifts[j]);
}
}
}
}
750 characters including whitespace
700 characters without whitespace
This post has been edited by wordswords: 26 December 2011 - 07:46 PM
#23
Re: Challenge: 12 Days of Christmas
Posted 26 December 2011 - 08:14 PM
public class A{public static void main(String[] a){String[] d ={ "first", "second", "third", "fourth", "fifth","sixth", "seventh", "eighth", "nineth", "tenth","eleventh", "twelveth" };String[] g={ "a partridge in a pear tree", "Two turtle doves","Three french hens", "Four calling birds", "Five golden rings","Six geese-a-laying", "Seven swans-a-swimming","Eight maids-a-milking", "Nine ladies dancing","Ten lords-a-leaping", "Eleven pipers piping","Twelve drummers drumming" };int i = 0;String r;for (;i<12;i++) {r="\nFor the "+d[i]+" day of Christmas, my true love gave to me:\n";int j=i;for(;j>-1;j--){if (i>0&&j==0)r=r+("and ");r=r+g[j]+"\n";}System.out.println(r);}}}
673 characters without whitespace..
#24
Re: Challenge: 12 Days of Christmas
Posted 26 December 2011 - 09:03 PM
Got it down to 1855 bytes. I could probably get it down a bit more by removing the CRLF's from a few strings and add them in code. Readability is out the door for this one but it assembles and works:
This post has been edited by GunnerInc: 26 December 2011 - 09:25 PM
#25
Re: Challenge: 12 Days of Christmas
Posted 26 December 2011 - 09:42 PM
#!/bin/bash
cardinal=(Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve)
ordinal=(first second third fourth fifth sixth seventh eighth nineth tenth
eleventh twelfth)
stuff=("turtle doves" "french hens" "calling birds" "golden rings"
"geese-a-laying" "swans-a-swimming" "maids-a-milking" "ladies dancing"
"lords-a-leaping" "pipers piping" "drummers drumming")
for (( i=0; i < ${#ordinal[@]}; ++i )) do
echo -e "On the ${ordinal[$i]} day of Christmas,\nMy true love gave to me,"
for (( j=i-1; j>=0; --j )) do
echo "${cardinal[$j]} ${stuff[$j]},"
done
[ $i -gt 0 ] && echo -n "And a " || echo -n "A "
echo -e "partridge in a pear tree.\n"
done
This post has been edited by anonymouscodder: 26 December 2011 - 09:44 PM
#26
Re: Challenge: 12 Days of Christmas
Posted 27 December 2011 - 12:16 PM
C#
class p{static void Main(){var s="";var d="1st/A Partrige in peartree/2nd/Two turtledove/3rd/Three french hens/4th/Four calling birds/5th/Five golden rings/6th/Six geese-a-laying/7th/Seven swans-a-swimming/8th/Eight maids-a-milking/9th/Nine ladies dancing/10th/Ten lords-a-leaping/11th/Eleven pipers piping/12th/Twelve drummers drumming".Split('/');for(var i=0;i<23;i+=2){s+="On the "+d[i]+" day of Christmas\nMy true love gave to me\n";for(var x=i+1;x>0;x-=2){s+=(i>0&&x<2?"And ":"")+d[x]+"\n";}s+="\n";}System.Console.WriteLine(s);}}
#27
Re: Challenge: 12 Days of Christmas
Posted 27 December 2011 - 12:38 PM
#28
Re: Challenge: 12 Days of Christmas
Posted 28 December 2011 - 11:21 AM
And it is in Java!
When removing all unneeded spaces, I get to: 650 Characters!
Here is the small code:
If you want to see the full code (for a better look on), here it is:
#29
Re: Challenge: 12 Days of Christmas
Posted 28 December 2011 - 08:43 PM
wordswords - no abbreviations but you can cut down on the punctuation (see my first post)
Here is my entry:
public class E {
public static void main(String[] args) {
String s = "";
int i;
for (int c : "าⅷྣ炇♃ⳃ妕ሗ䁖屼⌕䧣ങ撊屨䁲瑈喉盶ᤖḲẬ䤽庸➫崬宫彬宫⌨⻱ㄝ嵪䞫帬徫帨⎫攏帨徫㴚櫽旨ᱨ䌕唐ᱶ䌕䖐瑊⇨䔙㉣唓䱶㉬॑⋽㱱Ẳၶ⇣㉤॑㈽夌უパ॑ㄝ嵪ሃ壬ಃ㶐䖎瑊攖ศፖ໑塤䆚䖐瑊涖⅃⋈ಃ炏⨬➢⌬䥃⃯呱⨬瑖扉ᡵ㷤⨬ィ壵徢⊫⑨䔕൦䔋瑖䭗拣㻵ᱨ⌲ၖೱಝ咓㊷ⅇ䖃ಃᄓ屵ℕ"
.toCharArray())
while (c > 0) {
i = c & 31;
s += (char) (i < 3 ? 10 : i < 4 ? 32 : i + 93);
c >>= 5;
}
String[] S = s.split("z");
s = "";
for (i = 2; i < 14;)
System.out.println(S[0] + S[i] + S[1] + (s = S[27 - i++] + s));
}
}
Comes it at 381 chars with non-essential whitespace removed.
#30
Re: Challenge: 12 Days of Christmas
Posted 02 January 2012 - 04:13 AM
628 characters for me with no spaces
public class a
{
public static void main(String[] z)
{
String a = "\nOn the %s day of Christmas, my true love gave to me,\n";
String[][] b = { { "first", "second", "third", "forth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" },
{ "a partridge in a pear tree.", "Two turtle doves,", "Three french hens,", "Four calling birds,", "Five golden rings,", "Six geese-a-laying,", "Seven swans-a-swimming,", "Eight maids-a-milking,", "Nine ladies dancing,", "Ten lords-a-leaping,", "Eleven pipers piping,", "Twelve drummers drumming," } };
int n = 0;
for (int v = 0; v < 12;)
{
System.out.printf(a, b[0][v++]);
for (int k = 0; k <= n;)
System.out.println(b[1][n - k++]);
if (v == 1)
b[1][0] = "and " + b[1][0];
n++;
}
}
}
|
|

New Topic/Question
Reply



MultiQuote










|