This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Mathematical puzzle solved using Java

 
Ranch Hand
Posts: 630
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I found one mathematical funny query. Which I & my friend solving on paper in free time.
But I found challenging to write a program related to it.
See following image.

Fill numbers 1 to 8 in each box. But there are conditions as follows:-
1. specific number enter in box then neighboring box should not have its immediate number.
Example
1. If 'a' have 1 then its neighboring box are 'b', 'c', d','e'.  So those four box should not have number 2.
2. If 'd' have 1 then its neighboring box are 'a','b','c','e','g','h'.  So those four box should not have number 2. etc etc

Question are:-
1. Find total probability of accurate possibility. (I calculate total possibilities are 16777216.)
2. Print accurate set.

I will post when I complete my source code. I will try source with or without GUI.
If I stuck somewhere, then also I post reply for discuss.
If anyone know more questions which can be solved by java then share link.
It might help to refresh java programming.
 
Saloon Keeper
Posts: 5711
144
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most interesting (meaning: not too limited) programming languages can be used to solve the same set of problems, and Java is no exception.

If I were to solve this, I might resort to Prolog instead.
 
Saloon Keeper
Posts: 3413
149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Mandar,

just a few questions:

1) do you use all the 8 numbers 1...8, or is it allowed to have say 3 8's in the matrix?
2) if a = 2; then I assume that the neighboring cells (b, c, d, e) may not conrtain either 1 or 3
3) how did you get a total number of possibilities of 1.6M?
4) we have a dedicated forum for all things puzzles and programming 'programming diversions'. Have a look, I think you will like it.
 
Marshal
Posts: 65056
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mandar Khire wrote:. . . 2. If 'd' have 1 then its neighboring box are 'a','b','c','e','g','h'.  So those four box should not have number 2. etc etc

Foiur? Six, surely?

. . . . (I calculate total possibilities are 16777216.) . . ..

16777216 = 2²⁴, which suggests to me that the eight boxes don't have to contain distinct numbers, otherwise you would be calculating factorials.
 
Mandar Khire
Ranch Hand
Posts: 630
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for replying,

Tim Moores wrote:
If I were to solve this, I might resort to Prolog instead.


Prolog is very nice subject which I never used. Surely it will help to solve this problem.
But for me I first prefer basic java, then advance java. Same time I will study this new subject.

Piet Souris wrote:
1) do you use all the 8 numbers 1...8, or is it allowed to have say 3 8's in the matrix?


I am using 1 to 8 for each box. (1,2,3,4,5,6,7,8)
I dont know what is ' 3 8's in the matrix'.

Piet Souris wrote:
2) if a = 2; then I assume that the neighboring cells (b, c, d, e) may not conrtain either 1 or 3


Yes, same way apply for each cell/box.

Piet Souris wrote:
3) how did you get a total number of possibilities of 1.6M?


&

Campbell Ritchie wrote:

. . . . (I calculate total possibilities are 16777216.) . . ..

16777216 = 2²⁴, which suggests to me that the eight boxes don't have to contain distinct numbers, otherwise you would be calculating factorials.



Might I calculate with wrong formula.
I am trying to find out how many possibilities of putting 8 numbers in 8 boxes. So I use 8^8 =  16777216.
But Now I am searching right formula for find total possibilities.
Then i will apply another formula for find accurate possibilities from those total possibilities.
Need to refresh Maths knowledge also.
I found 1 link related to find possibilities might that formula right for this problem.
Permutation Formula

Piet Souris wrote:
4) we have a dedicated forum for all things puzzles and programming 'programming diversions'. Have a look, I think you will like it.



I never seen this section so I put this question in 'Beginning Java'. I decided to solve this problem with only basic java programming.
integer, arithmetic operations(addition, subtraction, division, multiplication), for, while, if-else etc only.
If I succeed then I move more optimize way. So understand importance of optimization.
As I thought. Might this way is not right way.
Need guidance from Java & Mathematics people.

Campbell Ritchie wrote:

Mandar Khire wrote:. . . 2. If 'd' have 1 then its neighboring box are 'a','b','c','e','g','h'.  So those four box should not have number 2. etc etc

Foiur? Six, surely?


Yes.
For simplicity as following:-
 
Bartender
Posts: 2326
100
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made a scratchpad for you :


output:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!