Jump to content

[Problem Solving #4] Lego Mosaics

wolfsinner

the outer loop should start from 2, not from 0

fValues[0] is lucky, and doesn't get modified, but fValues[1] gets set to 2, and screws up all the next calculations

alternatively, you can set fValues[1] = 0 before the loop, it should work that way too

 

i couldn't test it, but that looks like the problem to me

Thanks for helping out, I hope it worked, lets see if the webportal accepts it :D. I can't believe it was such a smal detail I couldn't figure out ^^ 

Nope its still incorrect :S However the fValues seem to be correct now.

Investigating...

Build log "Whiplash" : http://linustechtips.com/main/topic/158477-the-hero/

Whiplash: 4790k@4,4Ghz|Maximus VII Hero|4x4Gb Red/Black HyperX fury 1866Mhz|R9 290 Tri-X|Modded 450D|Sleeved cables on a M12II evo 850W|M500 480Gb| BenQ XL2411T@144Hz

Laptop: 4700MQ|16Gb@1600Mhz|Quadro 1100M|1080P|128Gb SSD|500Gb 7200RPM hdd

Link to comment
Share on other sites

Link to post
Share on other sites

Nope its still incorrect :S However the fValues seem to be correct now.

Investigating...

		//calculating the possibility		for(int i = 0; i<R;i++){			char lastColor = 'F';			int chainLength = 1;			char[] curLine = input.readLine().toCharArray();			char curColor = curLine[0];			for(int x = 0;x<C;x++){

mmm well, you assume that every line starts with an F color, which is not a very safe assumption

you should revise the block-lenght-reader, knowing that a row could start with any color, or it could even begin with an empty space

Link to comment
Share on other sites

Link to post
Share on other sites

mmm well, you assume that every line starts with an F color, which is not a very safe assumption

you should revise the block-lenght-reader, knowing that a row could start with any color, or it could even begin with an empty space

Well thats my bad, I didn't read carefully so I thought F was not a valid color. If I don't assignt lastColor a value it will throw a nullpointerexception... I'll take a look at it :)

 

edit:

		for(int i = 0; i<R;i++){			int chainLength = 1;			char[] curLine = input.readLine().toCharArray();			char lastColor = curLine[0];			char curColor;			for(int x = 1;x<C;x++){				curColor = curLine[x];				if(Character.isLetter(curColor)){					if(curColor == lastColor){						chainLength++;					}else{						lastColor = curColor;						possibilities = possibilities.multiply(BigInteger.valueOf(fValues[chainLength]));						chainLength=1;					}				}			}			possibilities = possibilities.multiply(BigInteger.valueOf(fValues[chainLength]));		}

Is something like this better? It gives me different results... 

edit2: its still wrong... :(

Build log "Whiplash" : http://linustechtips.com/main/topic/158477-the-hero/

Whiplash: 4790k@4,4Ghz|Maximus VII Hero|4x4Gb Red/Black HyperX fury 1866Mhz|R9 290 Tri-X|Modded 450D|Sleeved cables on a M12II evo 850W|M500 480Gb| BenQ XL2411T@144Hz

Laptop: 4700MQ|16Gb@1600Mhz|Quadro 1100M|1080P|128Gb SSD|500Gb 7200RPM hdd

Link to comment
Share on other sites

Link to post
Share on other sites

-snip-

the problem now is when the row begins with an empty space

currently, your program considers that case as a 1-length block

now that i think of it, it shouldn't be a problem since fValues[1] = 1

 

so... i dunno

try to print out the block-lengths and see if they're correct

Link to comment
Share on other sites

Link to post
Share on other sites

the problem now is when the row begins with an empty space

currently, your program considers that case as a 1-length block

now that i think of it, it shouldn't be a problem since fValues[1] = 1

 

so... i dunno

try to print out the block-lengths and see if they're correct

I'll try, the strange thing is that it outputs the correct amount of possibilities with the two examples. So I think the problem might be the fValues, can you post (or pm) me the first 20 or so so I can check if they're correctt? (A)

 

edit: I think the blocklenghts are correct...

Build log "Whiplash" : http://linustechtips.com/main/topic/158477-the-hero/

Whiplash: 4790k@4,4Ghz|Maximus VII Hero|4x4Gb Red/Black HyperX fury 1866Mhz|R9 290 Tri-X|Modded 450D|Sleeved cables on a M12II evo 850W|M500 480Gb| BenQ XL2411T@144Hz

Laptop: 4700MQ|16Gb@1600Mhz|Quadro 1100M|1080P|128Gb SSD|500Gb 7200RPM hdd

Link to comment
Share on other sites

Link to post
Share on other sites

I'll try, the strange thing is that it outputs the correct amount of possibilities with the two examples. So I think the problem might be the fValues, can you post (or pm) me the first 20 or so so I can check if they're correctt? (A)

 

edit: I think the blocklenghts are correct...

i was starting to lose my mind over this

the problem is that your method counts

ABCCC...CCCDE

as a 6-long block

Link to comment
Share on other sites

Link to post
Share on other sites

Hmm okay thanks!

 

I lost my mind already over this.... Oh wait what mind?

 

I'll take a look at it, but does Character.isLetter return true for (.)?

Build log "Whiplash" : http://linustechtips.com/main/topic/158477-the-hero/

Whiplash: 4790k@4,4Ghz|Maximus VII Hero|4x4Gb Red/Black HyperX fury 1866Mhz|R9 290 Tri-X|Modded 450D|Sleeved cables on a M12II evo 850W|M500 480Gb| BenQ XL2411T@144Hz

Laptop: 4700MQ|16Gb@1600Mhz|Quadro 1100M|1080P|128Gb SSD|500Gb 7200RPM hdd

Link to comment
Share on other sites

Link to post
Share on other sites

I'll take a look at it, but does Character.isLetter return true for (.)?

nope

Link to comment
Share on other sites

Link to post
Share on other sites

nope

I changed it to this

				if(Character.isLetter(curColor)){					if(curColor == lastColor){						chainLength++;					}else{						//if(chainLength>1){System.out.println(chainLength);System.out.println(possibilities);};						lastColor = curColor;						possibilities*=fValues[chainLength];						chainLength=1;					}				}else{					chainLength=1;				} 

 

But it still says its wrong...

Build log "Whiplash" : http://linustechtips.com/main/topic/158477-the-hero/

Whiplash: 4790k@4,4Ghz|Maximus VII Hero|4x4Gb Red/Black HyperX fury 1866Mhz|R9 290 Tri-X|Modded 450D|Sleeved cables on a M12II evo 850W|M500 480Gb| BenQ XL2411T@144Hz

Laptop: 4700MQ|16Gb@1600Mhz|Quadro 1100M|1080P|128Gb SSD|500Gb 7200RPM hdd

Link to comment
Share on other sites

Link to post
Share on other sites

I changed it to this

-snip-

But it still says its wrong...

this way it ignores the block before the dots, so

ABCCC...CCCDE

counts just as a 3-long block

Link to comment
Share on other sites

Link to post
Share on other sites

this way it ignores the block before the dots, so

ABCCC...CCCDE

counts just as a 3-long block

I think I've spend to much time trying to figure it out why it doens't work :P this are such stupid little embarrasing things, normally I would see them.

 

Let me get some coffee, then I'll take a look at it :)

 

edit: It still says its wrong.... However it gives 16 for your example (ABCCC...CCCDE) which is correct right?

 

code:

import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.math.BigInteger;public class LEGO_Mosaics {	public static void main(String[] args) throws IOException{		String inputLocation = "C:/INPUT/t7.txt";		int[] bricks = {1, 2, 3, 4, 6, 8, 10, 12, 16};		BufferedReader input = new BufferedReader(new FileReader(inputLocation));		long possibilities = 1;		String[] firstLine = input.readLine().split(" ");		int R = Integer.parseInt(firstLine[0]);		int C = Integer.parseInt(firstLine[1]);		//To make sure we don't get ArrayIndexOutOfBoundExceptions		long[] fValues = new long[C+1];		//setting the values for f		fValues[0] = 1;		fValues[1] = 1;		for(int i = 2;i<= C;i++){			for(int x = 0; x<bricks.length && i-bricks[x]>= 0; x++){				fValues[i]+=fValues[i-bricks[x]];			}		}		//calculating the possibility		for(int i = 0; i<R;i++){			int chainLength = 1;			char[] curLine = input.readLine().toCharArray();			char lastColor = curLine[0];			char curColor;			for(int x = 1;x<C;x++){				curColor = curLine[x];					if(curColor == lastColor && Character.isLetter(curColor)){						chainLength++;					}else{						lastColor = curColor;						possibilities*=fValues[chainLength];						chainLength=1;					}			}			possibilities*=fValues[chainLength];		}		System.out.println(possibilities);	}} 

Build log "Whiplash" : http://linustechtips.com/main/topic/158477-the-hero/

Whiplash: 4790k@4,4Ghz|Maximus VII Hero|4x4Gb Red/Black HyperX fury 1866Mhz|R9 290 Tri-X|Modded 450D|Sleeved cables on a M12II evo 850W|M500 480Gb| BenQ XL2411T@144Hz

Laptop: 4700MQ|16Gb@1600Mhz|Quadro 1100M|1080P|128Gb SSD|500Gb 7200RPM hdd

Link to comment
Share on other sites

Link to post
Share on other sites

edit: It still says its wrong.... However it gives 16 for your example (ABCCC...CCCDE) which is correct right?

Yes, 16 is correct for that example. When submitting make sure you put a single linebreak after each answer.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

edit: It still says its wrong.... However it gives 16 for your example (ABCCC...CCCDE) which is correct right?

i'm sure that after correcting that bug the program works correctly, i ran it on my pc yesterday and the results were correct

as fizzlesticks said, doublecheck the format of your submissions, you wouldn't be the first to do that distraction error

Link to comment
Share on other sites

Link to post
Share on other sites

Well, thanks for the help both! The linebreak did it...

:D

Build log "Whiplash" : http://linustechtips.com/main/topic/158477-the-hero/

Whiplash: 4790k@4,4Ghz|Maximus VII Hero|4x4Gb Red/Black HyperX fury 1866Mhz|R9 290 Tri-X|Modded 450D|Sleeved cables on a M12II evo 850W|M500 480Gb| BenQ XL2411T@144Hz

Laptop: 4700MQ|16Gb@1600Mhz|Quadro 1100M|1080P|128Gb SSD|500Gb 7200RPM hdd

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×