- PR -

Look! Ma' the script can compute!

投稿者投稿内容
Oregon
ベテラン
会議室デビュー日: 2001/08/01
投稿数: 52
お住まい・勤務地: Tualatin 97062
投稿日時: 2001-09-21 03:38
"Mathematical Goodbye" by Mori Hiroshi has this quiz:
suppose five balls are numbered and linked in a ring,
sum the numbers of balls that are in consequtive places.
when the sums range all the numbers from 1 to 21,
find the numbers.

hints:
there is a ball numbered "1"
there is a ball numbered "2"

extra credit:
program in w2k batch script.
Oregon
ベテラン
会議室デビュー日: 2001/08/01
投稿数: 52
お住まい・勤務地: Tualatin 97062
投稿日時: 2001-09-21 03:43
need more hint?

the maximum number is 10.

solution is unique taking into account order/symmetry

good luck!
H2
ぬし
会議室デビュー日: 2001/09/06
投稿数: 586
お住まい・勤務地: 港
投稿日時: 2001-09-21 11:01
Hi Oregon,

Yes I have worked the answer out. It was fun! I used a simple breadth first search technique to find the answer. Should I post the answer here now? Or Should I wait for others to enjoy this question?

I don't know how to write windows batch script, so I didn't do that. If you are interested, I can write a Java program to find the answer.

[ メッセージ編集済み 編集者: H2 編集日時 2001-09-21 11:11 ]
Oregon
ベテラン
会議室デビュー日: 2001/08/01
投稿数: 52
お住まい・勤務地: Tualatin 97062
投稿日時: 2001-09-23 08:33
引用:

H2さんの書き込み (2001-09-21 11:01) より:
...Yes I have worked the answer out. It was fun! I used a simple breadth first search technique to find the answer.


good to hear!
mine is a horse-deer search and human post-process to identify the uniqueness.

引用:

Should I post the answer here now? Or Should I wait for others to enjoy this question?


how thoughtful, but I don't care. we're free and all up to you.

引用:

I don't know how to write windows batch script, so I didn't do that. If you are interested, I can write a Java program to find the answer.


love to see that! maybe you can crosspost it to "Java Solutions" as well.


extra credit (2): if we say the original problem N(5)=21, what is N(6)?
H2
ぬし
会議室デビュー日: 2001/09/06
投稿数: 586
お住まい・勤務地: 港
投稿日時: 2001-09-23 19:37
I have made the java program. You can download it at my home page, here(English) OR 日本語ページへ. I put a lot of comments on the source, so people can understand what I am doing. Pleas ask me any questions if code is not understandable.

You can compile it by:
コード:

> javac TwentyOne.java


and run the program by:
コード:

> java TwentyOne



It will use breadth first search that I used to find the solution. The program is very inflexible as it only solves the same problem over and over. The output will never change .

I explain what I did. (because TwentyOne does exactly the samething as I did, you can follow the source, too)
1. fix 1 at one of the ball as we know 1 has to go somewhere
2. pick any place for 2, again, because we know 2 has to be somewhere
3. now, pick a number between 3 and 10
4. place that number picked at one of the ball which are not used yet
5. Add 1, 2 and number we picked at step 3
6. list all the combination of number that can sum up to 21 with the sum that we found in step 5
7. place the numbers of combinations on the ball
8. test them if they can make the numbers go to step 11 if solution is found
9. if none of them work, then go back to step 3 pick another number and repeat
10 if all numbers were tried, go back to step 2 and pick different place for it and repeat
11. FINISH!

Since, the program is very inflexible, it only solves N(5). I think I can modify it to find the other question, but I have not enough time for it at moment, I'll try if I have time.

引用:

Oregonさんの書き込み (2001-09-23 08:33) より:
mine is a horse-deer search and human post-process to identify the uniqueness.


What is horse-deer search? I have never heard of it. I am very curious.

[ メッセージ編集済み 編集者: H2 編集日時 2001-09-23 19:38 ]

[ メッセージ編集済み 編集者: H2 編集日時 2001-09-23 19:38 ]
Oregon
ベテラン
会議室デビュー日: 2001/08/01
投稿数: 52
お住まい・勤務地: Tualatin 97062
投稿日時: 2001-09-27 08:40
H2 figured it right.

hers' my code in w2k script based on BAKA search
コード:
@echo off
for /L %%a in (1 1 9) do (
	for /L %%b in (1 1 9) do (
		for /L %%c in (1 1 9) do (
			for /L %%d in (1 1 9) do (
				set /A t=%%a + %%b + %%c + %%d
				if !t!==16 call o_it 0 %%a %%b %%c %%d
			)
		)
	)
)
goto :eof

:do_it
set vals=%1%2%3%4%5
set hits=11111111111111111111
for /L %%i in (0 1 4) do (
	::case only one ball in series
	call :get_val v %%i 
	call :hit_it !v!
	::case four balls (complement of case one)
	set /A w=21 - !v!
	call :hit_it !w!
	::case two balls in series
	call :get_next j %%i
	call :get_val u !j! 
	set /A w=!u! + !v!
	call :hit_it !w!
	::case three balls (complement of case two)
	set /A w=21 - !w!
	call :hit_it !w!
)
if !hits!==00000000000000000000 (
	set /A aa=%2 + 1
	set /A bb=%3 + 1
	set /A cc=%4 + 1
	set /A dd=%5 + 1
	echo 1 !aa! !bb! !cc! !dd!
)
goto :eof

:get_val
set /A %1=!vals:~%2,1! + 1
goto :eof

:hit_it
set /A len=%1 - 1
set /A rem=%1
set left=!hits:~0,%len%!
set hits=!left!0!hits:~%rem%!
goto :eof

:get_next
set /A %1=(%2 + 1) %% 5
goto :eof

H2
ぬし
会議室デビュー日: 2001/09/06
投稿数: 586
お住まい・勤務地: 港
投稿日時: 2001-09-27 09:00
OH!! I got it. Horse(馬)&Deer(鹿) Search!!
I didn't realize...
Oregon
ベテラン
会議室デビュー日: 2001/08/01
投稿数: 52
お住まい・勤務地: Tualatin 97062
投稿日時: 2001-09-28 00:06
N(4)=13 (2 solutions: max element 7)
[1 2 6 4]
[1 3 2 7]

N(5)=21 (1 sol: max: 10)
[1 2 10 2 5]

N(6)=31 (5 sol: max: 14)
[1 2 5 4 6 13]
[1 2 7 4 12 5]
[1 3 2 7 8 10]
[1 3 6 2 5 14]
[1 7 3 2 4 14]

N(7)=?

any one? I dare not try in w2k script on my PC.

スキルアップ/キャリアアップ(JOB@IT)