Challenge: 12 Days of Christmas

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

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

#31 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 247
  • Joined: 29-November 08

Re: Challenge: 12 Days of Christmas

Posted 08 April 2012 - 05:21 PM

I'm a assuming using GolfScript or J is cheating?
Was This Post Helpful? 0
  • +
  • -

#32 cfoley  Icon User is online

  • Cabbage
  • member icon

Reputation: 2045
  • View blog
  • Posts: 4,233
  • Joined: 11-December 07

Re: Challenge: 12 Days of Christmas

Posted 19 April 2012 - 08:33 AM

Salient points from the opening post:

Quote

I wanted to make a just-for-fun challenge...

Have fun!


;)

This post has been edited by cfoley: 19 April 2012 - 08:33 AM

Was This Post Helpful? 0
  • +
  • -

#33 extremeblueness  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 186
  • Joined: 22-October 12

Re: Challenge: 12 Days of Christmas

Posted 01 December 2012 - 10:16 AM

798 was my attempt with my month and a half of Java knowledge:

class D
{
    static void d()
    {
        String a = "On the ", b = "first", c = "second", d = "third", e = "fourth",
               f = "fifth", g = "sixth", h = "seventh", i = "eighth",
               j = "ninth", k = "tenth", l = "eleventh", m = "twelth",
               n = " day of Christmas\nMy true love gave to me\n",
               o = "And a partridge in a pair tree\n",
               p = "Two turtle doves\n", q = "Three french hens\n",
               r = "Four calling birds\n", s = "Five golden rings\n",
               t = "Six geese a laying\n", u = "Seven swans a swimming\n",
               v = "Eight maids a milking\n", w = "Nine ladies dancing\n",
               x = "Ten lords a leaping\n", y = "Eleven pipers piping\n",
               z = "\n";
        System.out.print(a + b + n + "A partridge in a pair tree\n" + z +
                         a + c + n + p + o + z +
                         a + d + n + q + p + o + z +
                         a + e + n + r + q + p + o + z +
                         a + f + n + s + r + q + p + o + z +
                         a + g + n + t + s + r + q + p + o + z +
                         a + h + n + u + t + s + r + q + p + o + z +
                         a + i + n + v + u + t + s + r + q + p + o + z +
                         a + j + n + w + v + u + t + s + r + q + p + o + z +
                         a + k + n + x + w + v + u + t + s + r + q + p + o + z +
                         a + l + n + y + x + w + v + u + t + s + r + q + p + o + z +
                         a + m + n + "Twelve drummers drumming\n" + y + x + w + v + u + t + s + r + q + p + o + z);
    }
}

Was This Post Helpful? 1
  • +
  • -

#34 Kemical  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 7
  • Joined: 27-November 12

Re: Challenge: 12 Days of Christmas

Posted 04 December 2012 - 03:39 AM

I am gonna redo it without the getDigit() method but that will have to wait for another night.

1352 with the getDigit() ignoring spaces

Aprox 720 without getDigit().

public class Christmas
{
public static void main(String[] args)
{
	String t[] = {"And a partridge in a pear tree.", "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,",
		"day of Christmas.\nMy true love gave to me","On the "};
	int i =1;
	int s =0;
	int p=0;

	for(;i<12;i++)
	{	
		if(p==0)
		{
			System.out.println(t[13] + getDigit(i, s+1) +t[12]);

			System.out.println("A " + t[0].substring(6,30));
			p++;
		}
		System.out.println(t[13] + getDigit(i+1, s+1) + t[12]);

		for(int x=i;x>=0;x--)
		{

		System.out.println( getDigit(x+1,s) + " " + t[x]);
		}
		System.out.println();

	}
	System.out.println(t[13] + getDigit(i, s+1) + t[12]);

	for(;i>0;i--)
	{
		System.out.println(getDigit(i,s) + " " + t[i-1]);
	}




}


private static  String getDigit(int i, int s)
{
	String o= "";
	if(i==1&&s==0)
		return "";
	else if(i==1&&s==1)
		return "First";
	else if (i==2&&s ==0)
		return "Two";
	else if (i==2 && s==1)
		return "Second";
	else if (i==3 && s==0)
		return "Three";
	else if (i==3 && s==1)
		return "Third";
	else if(i==4)
		o="Four";
	else if (i==5&&s==0)
		o="Five";
	else if (i==5&&s==1)
		o="Fith";
	else if (i ==6)
		o="Six";
	else if (i==7)
		o="Seven";
	else if (i ==8&& s==0)
		o="Eight";
	else if (i==8 && s==1)
		o="Eighth";
	else if (i==9&&s==0)
		o="Nine";
	else if (i==9&&s==1)
		o="Ninth";
	else if (i==10)
		o="Ten";
	else if (i==11)
		o="Eleven";
	else if (i==12&&s==0)
		o="Twelve";
	else if (i==12 &&s==1)
		o="Twelfth";
	else;

	if((i==4|| i==6||i==7||i==10||i==11)&&s==1)
		o += "th";
	return o;
}
}


Was This Post Helpful? 0
  • +
  • -

#35 Reoboss  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-December 12

Re: Challenge: 12 Days of Christmas

Posted 26 December 2012 - 09:47 PM

I'm pretty new to coding, so I did make a very simple code with a print line command. It's simple, but I did it the hard way.

public class TDC_challenge 
{
	public static void main(String args[])
	{
		for(int count = 1; count <= 12; count++)
		{
			 
			System.out.println("On the " + (count == 1 ? "first": count == 2 ? 
					"second": count == 3 ? "third": count == 4 ? "fourth": count == 5 ? "fifth": count == 6 ? 
							"sixth": count == 7 ? "seventh": count == 8 ? "eighth": count == 9 ? 
									"ninth": count == 10 ? "tenth": count == 11 ? "eleventh": "twelfth") 
									+ " day of Christmas,\nmy true love gave to me,\n" + (count == 1 ? "a partridge in a pear tree\n\n": count == 2 ? 
					"two turtle doves,\nand a partridge in a pear tree\n\n": count == 3 ? "three french hens,\ntwo turtle doves,\nand a partridge in a pear tree\n\n": count == 4 ? 
							"four calling birds,\nthree french hens,\ntwo turtle doves,\nand a partridge in a pear tree\n\n": count == 5 ? 
									"five golden rings,\nfour calling birds,\nthree french hens,\ntwo turtle doves,\nand a partridge in a pear tree\n\n": count == 6 ? 
							"six geese a-laying,\nfive golden rings,\nfour calling birds,\nthree french hens,\ntwo turtle doves,\nand a partridge in a pear tree\n\n": count == 7 ? 
									"seven swans a-swimming,\nsix geese a-laying,\nfive golden rings,\nfour calling birds,\nthree french hens,\ntwo turtle doves,\nand a partridge in a pear tree\n\n": count == 8 ? 
											"eight maids a-milking,\nseven swans a-swimming,\nsix geese a-laying,\nfive golden rings,\nfour calling birds,\nthree french hens,\ntwo turtle doves,\nand a partridge in a pear tree\n\n": count == 9 ? 
									"nine ladies dancing,\neight maids a-milking,\nseven swans a-swimming,\nsix geese a-laying,\nfive golden rings,\nfour calling birds,\nthree french hens,\ntwo turtle doves,\nand a partridge in a pear tree\n\n": count == 10 ? 
											"ten lords a-leaping,\nnine ladies dancing,\neight maids a-milking,\nseven swans a-swimming,\nsix geese a-laying,\nfive golden rings,\nfour calling birds,\nthree french hens,\ntwo turtle doves,\nand a partridge in a pear tree\n\n": count == 11 ? 
													"eleven pipers piping,\nten lords a-leaping,\nnine ladies dancing,\neight maids a-milking,\nseven swans a-swimming,\nsix geese a-laying,\nfive golden rings,\nfour calling birds,\nthree french hens,\ntwo turtle doves,\nand a partridge in a pear tree\n\n": 
														"twelve drummers drumming,\neleven pipers piping,\nten lords a-leaping,\nnine ladies dancing,\neight maids a-milking,\nseven swans a-swimming,\nsix geese a-laying,\nfive golden rings,\nfour calling birds,\nthree french hens,\ntwo turtle doves,\nand a partridge in a pear tree\n\n"));
			
		}
	}

}


Was This Post Helpful? 0
  • +
  • -

#36 nonybrighto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-December 12

Re: Challenge: 12 Days of Christmas

Posted 31 December 2012 - 05:56 AM

i have done this in java before now do you want my code or you want clues to do it yourself?

i used arrays
Was This Post Helpful? 0
  • +
  • -

#37 nonybrighto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-December 12

Re: Challenge: 12 Days of Christmas

Posted 31 December 2012 - 06:03 AM

this is my code but just change my lyrics..lol.... i know they are wrong, i didnt know how to sing the song.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author NONY
 */
public class Chrismas {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        String result=" ";
        String[] daytalk={" ","a patric in a palm tree. ","two turtle rats, ",
                          "three fowls,","four calling birds,",
                          "five golden rings","six geeze a laying",
                          "7","8","9","10","11","12"};
        String[] days={" ","first","second","third","fourth","fifth","sixth","seventh","eight","ninth","tenth","eleventh","twelvth"};
        String onthe="On the ";
        String chris=" day of christmas my true luv sent to me ";
        for(int day=1;day<=12;day++)
        {
            switch(day)
            {
                case 1:
                    result=result+daytalk[1]; 
                   System.out.println(onthe+days[day]+chris+result);
                    break;
                case 2:
                    result=daytalk[2]+result;
                    System.out.println(onthe+days[day]+chris+result);
                    break;
                case 3:
                    result=daytalk[3]+result;
                    System.out.println(onthe+days[day]+chris+result);
                    break;    
               case 4:
                    result=daytalk[4]+result;
                    System.out.println(onthe+days[day]+chris+result);
                    break;   
                case 5:
                    result=daytalk[5]+result;
                    System.out.println(onthe+days[day]+chris+result);
                    break; 
               case 6:
                    result=daytalk[6]+result;
                    System.out.println(onthe+days[day]+chris+result);
                    break; 
               case 7:
                    result=daytalk[7]+result;
                    System.out.println(onthe+days[day]+chris+result);
                    break; 
              case 8:
                    result=daytalk[8]+result;
                    System.out.println(onthe+days[day]+chris+result);
                    break; 
             case 9:
                    result=daytalk[9]+result;
                    System.out.println(onthe+days[day]+chris+result);
                    break; 
             case 10:
                    result=daytalk[10]+result;
                    System.out.println(onthe+days[day]+chris+result);
                    break; 
            case 11:
                    result=daytalk[11]+result;
                    System.out.println(onthe+days[day]+chris+result);
                    break; 
            case 12:
                    result=daytalk[12]+result;
                    System.out.println(onthe+days[day]+chris+result);
                    break;     
                    
            }
        }
        
    }
}


This post has been edited by macosxnerd101: 01 January 2013 - 01:52 PM
Reason for edit:: Don't forget to use code tags

Was This Post Helpful? 0
  • +
  • -

#38 John120  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 09-January 13

Re: Challenge: 12 Days of Christmas

Posted 14 January 2013 - 06:14 AM

Hi,
I know it is a little late but here is my answer:
        String[] numbers = {"first", "second", "third", "fourth", "fifth", "sixth",
            "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"};
        String[] text = { "And a partridge in a pear tree\n", "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"};
        String song1 ="On the ";
        String song2 =" day of Christmas,\nMy true love gave to me,\n";
        
        for (int i = 0; i < 12; i++) {
            System.out.println(song1 + numbers[i] + song2 + text[i]);
            for (int j = i - 1; j > -1; j--) {
                System.out.println(text[j]);
            }
        }


Was This Post Helpful? 0
  • +
  • -

#39 extremeblueness  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 186
  • Joined: 22-October 12

Re: Challenge: 12 Days of Christmas

Posted 15 January 2013 - 06:25 AM

Nice. You're the only one without a scroll bar in your code snippet.
Was This Post Helpful? 0
  • +
  • -

#40 cfoley  Icon User is online

  • Cabbage
  • member icon

Reputation: 2045
  • View blog
  • Posts: 4,233
  • Joined: 11-December 07

Re: Challenge: 12 Days of Christmas

Posted 15 January 2013 - 06:44 AM

View Postextremeblueness, on 15 January 2013 - 01:25 PM, said:

Nice. You're the only one without a scroll bar in your code snippet.


Certainly the only one this year without a scroll bar. ;)
Was This Post Helpful? 0
  • +
  • -

#41 lego freak17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-July 13

Re: Challenge: 12 Days of Christmas

Posted 21 July 2013 - 12:30 PM

public static void main(String args[]){
    String[] days = {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"};
    String ans = "";
     for(int i=1; i<=12; i++){
      ans+="On the "+days[i-1]+" day of Christmas,\nmy true love gave to me,\n";
      switch(i){
        case 12: ans += "Twelve drummers drumming, \n";
        case 11: ans += "Eleven pipers piping, \n";
        case 10: ans += "Ten lords a-leaping, \n";
        case  9: ans += "Nine ladies dancing,\n";
        case  8: ans += "Eight maids a-milking,\n";
        case  7: ans += "Seven swans a-swimming,\n";
        case  6: ans += "Six geese a-laying,\n";
        case  5: ans += "Five GOLDEN RINGS!\n";
        case  4: ans += "Four colly birds, \n";
        case  3: ans += "Three french hens,\n";
        case  2: ans += "Two turtle doves,\nand ";
        case  1: ans += "A partridge in a pear tree. \n";
        break;}
        ans+="\n";}
     System.out.println(ans);}}

Was This Post Helpful? 0
  • +
  • -

#42 cppnewb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 13

Re: Challenge: 12 Days of Christmas

Posted 27 October 2013 - 09:11 PM

I know, old thread. but I needed a distraction.
public class Delete {
    public static void main(String[] args) {
        String[] stringArray = new String[]{"On the first day of Christmas, \n"," my true love gave to me,\n", " A partridge in a pear tree. ",
        "\n\n\n On the second day of Christmas, \n"," my true love gave to me, \n"," Two turtle doves,  \n"," And a partridge in a pear tree.  \n",
        "\n\n\n  On the twelfth day of Christmas,", " My true love gave to me, \n", " Twelve drummers drumming, \n", "Eleven pipers piping,\n",
        " Ten lords-a-leaping, \n"," Nine ladies dancing,\n"," Eight maids-a-milking, \n", " Seven swans-a-swimming,\n", " Six geese-a-laying, \n",
        " Five golden rings, \n"," Four calling birds, \n"," Three french hens, \n", " Two turtle doves,"," And a partridge in a pear tree."};
        for(int i = 0; i < stringArray.length; i++){
            System.out.println(stringArray[i]);
        }
    }  
}


11 lines, printing to cmd line, storing the verses in a string array.
Was This Post Helpful? 0
  • +
  • -

#43 PenguinRage  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 29-November 13

Re: Challenge: 12 Days of Christmas

Posted 29 November 2013 - 11:13 PM

Hey everyone,
I'm an amateur as well but here is my attempt. 996 characters :stupid: sadly not short enough.

Spoiler

Was This Post Helpful? 1
  • +
  • -

#44 floppyspace  Icon User is offline

  • D.I.C Regular

Reputation: 48
  • View blog
  • Posts: 254
  • Joined: 04-February 10

Re: Challenge: 12 Days of Christmas

Posted 01 December 2013 - 08:49 PM

I saw this post has been necro'd a few times over the past few years so I though why not since it is near that time once again.

My submission uses Jsoup and pastebin :)/>/>/>

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class TheTwelveDays {

	public static void main(String[] args) {
		
		String url = "http://pastebin.ca/2487409";
		try {
			Document doc = Jsoup.connect(url).get();
			Elements input = doc.select("textarea[class=pastecontent]");
			System.out.print(input); 
		} catch (IOException e) {		
			System.out.println("Failed to launch because of cfoley ;)/> ");
			e.printStackTrace();
		}

		
	}

}


Merry Christmas and pow! :P/>/>/>

This post has been edited by floppyspace: 02 December 2013 - 04:15 AM

Was This Post Helpful? 0
  • +
  • -

#45 cfoley  Icon User is online

  • Cabbage
  • member icon

Reputation: 2045
  • View blog
  • Posts: 4,233
  • Joined: 11-December 07

Re: Challenge: 12 Days of Christmas

Posted 02 December 2013 - 01:44 AM

Ha ha. How many lines of code make up Jsoup and pastebin? I think we should include those in the total. :P

I'm actually really pleased whenever this gets bumped with a new submission.
Was This Post Helpful? 0
  • +
  • -

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