Challenge: 12 Days of Christmas

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

49 Replies - 35428 Views - Last Post: 30 April 2014 - 11:18 AM

#16 Sheph  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,020
  • Joined: 12-October 11

Re: Challenge: 12 Days of Christmas

Posted 21 December 2011 - 11:24 PM

How long is this one?
Spoiler
Edit: I don't know how to find the number of chars, but saving it to notepad in its completely stripped (but still syntactically correct form), I got 649 byte file. I'm assuming that's the number of chars? Anyone know how I can verify?

This post has been edited by Sheph: 22 December 2011 - 12:32 AM

Was This Post Helpful? 1
  • +
  • -

#17 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,433
  • Joined: 29-May 08

Re: Challenge: 12 Days of Christmas

Posted 22 December 2011 - 10:07 AM

Sheph: Generally it the count of non-whitespace chars.
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

Was This Post Helpful? 1
  • +
  • -

#18 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1152
  • View blog
  • Posts: 2,530
  • Joined: 05-May 05

Re: Challenge: 12 Days of Christmas

Posted 22 December 2011 - 10:28 AM

@Sheph: Why not use a character counter website? Delete the white space yourself. Purely speculation, but the file size may reflect character encodings, so it may not be the *correct* way to determine character count if your using characters outside the Basic Multilingual Plane.

This post has been edited by blackcompe: 27 December 2011 - 03:13 AM

Was This Post Helpful? 2
  • +
  • -

#19 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: Challenge: 12 Days of Christmas

Posted 22 December 2011 - 07:04 PM

Don't think I can get the lowest number of characters, but this how I would do it in Assembly. Scratch the source I have in the zip up there, I changed to this:
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

Was This Post Helpful? 2
  • +
  • -

#20 Sheph  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,020
  • Joined: 12-October 11

Re: Challenge: 12 Days of Christmas

Posted 22 December 2011 - 07:45 PM

Ok. Update on my code. I forgot to add "day" in day of christmas. I fixed it and changed a few things. I used the website you suggested, blackcompe, and this is executable java code that gives proper output at 644 characters. (If you want readable code, go to my previous post :) )

Spoiler


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

Was This Post Helpful? 1
  • +
  • -

#21 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1152
  • View blog
  • Posts: 2,530
  • Joined: 05-May 05

Re: Challenge: 12 Days of Christmas

Posted 23 December 2011 - 10:29 PM

1593 characters stripped in MIPS assembly.

Spoiler

This post has been edited by blackcompe: 23 December 2011 - 10:41 PM

Was This Post Helpful? 1
  • +
  • -

#22 wordswords  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 76
  • View blog
  • Posts: 272
  • Joined: 17-December 11

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

Was This Post Helpful? 1
  • +
  • -

#23 wordswords  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 76
  • View blog
  • Posts: 272
  • Joined: 17-December 11

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..
Was This Post Helpful? 1
  • +
  • -

#24 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: Challenge: 12 Days of Christmas

Posted 26 December 2011 - 09:03 PM

Used to be 3934 bytes (chars)
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:
Spoiler

This post has been edited by GunnerInc: 26 December 2011 - 09:25 PM

Was This Post Helpful? 1
  • +
  • -

#25 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

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

Was This Post Helpful? 1
  • +
  • -

#26 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,433
  • Joined: 29-May 08

Re: Challenge: 12 Days of Christmas

Posted 27 December 2011 - 12:16 PM

I think this first sub 500 char one (at 497)
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);}}


Was This Post Helpful? 1
  • +
  • -

#27 wordswords  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 76
  • View blog
  • Posts: 272
  • Joined: 17-December 11

Re: Challenge: 12 Days of Christmas

Posted 27 December 2011 - 12:38 PM

Are you allowed to use abbreviations, ie: 12th instead of twelfth?
Was This Post Helpful? 0
  • +
  • -

#28 Sinned  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 207
  • Joined: 13-October 10

Re: Challenge: 12 Days of Christmas

Posted 28 December 2011 - 11:21 AM

I wrote my code, satisfies all requirements.
And it is in Java!

When removing all unneeded spaces, I get to: 650 Characters!

Here is the small code:
Spoiler


If you want to see the full code (for a better look on), here it is:
Spoiler

Was This Post Helpful? 1
  • +
  • -

#29 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1948
  • View blog
  • Posts: 4,048
  • Joined: 11-December 07

Re: Challenge: 12 Days of Christmas

Posted 28 December 2011 - 08:43 PM

Thanks for all the replies and entries so far!

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.
Was This Post Helpful? 2
  • +
  • -

#30 Mylo  Icon User is offline

  • Knows all, except most.

Reputation: 265
  • View blog
  • Posts: 747
  • Joined: 11-October 11

Re: Challenge: 12 Days of Christmas

Posted 02 January 2012 - 04:13 AM

Nice cfoley!

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++;
		}

	}
}



Was This Post Helpful? 1
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4