vak: (Default)
[personal profile] vak
В качестве субботнего развлечения сваял простейшую игру "быки и коровы" на Си. На самом деле перепёр с Бейсика. Исходник здесь: bulls-and-cows.c. Сыграем:
$ cc -O bulls-and-cows.c -o bulls-and-cows
$ ./bulls-and-cows
Guess a number.
3210
You scored 0 bulls and 1 cows.
Guess a number.
6541
You scored 1 bulls and 1 cows.
Guess a number.
6187
You scored 0 bulls and 0 cows.
Guess a number.
9534
You scored 1 bulls and 2 cows.
Guess a number.
4592
You scored 4 bulls and 0 cows.
Correct. That took you 5 guesses.
Самому думать лень, проще задействовать решатель из интернета: kuniga.me/bulls_and_cows/

A Bulls and Cows Solver

If you are not familiar with this game, check this Wikipedia article.

How to use the solver. Think of a 4-digit number with no repeated digits. Then choose the outcome (x, y) in the dropdown below, where x is the number of digits the solver got right AND in the right position (bulls), and y be the number of digits it got right but in the wrong position (cows).

If you are interested in the implementation of the solver, check our blog post.

Guessed: [3,2,1,0], result: (0, 1)
Guessed: [6,5,4,1], result: (1, 1)
Guessed: [6,1,8,7], result: (0, 0)
Guessed: [9,5,3,4], result: (1, 2)
Guessed: [4,5,9,2], result: (4, 0)

Solved! The secret is: [4,5,9,2]
Теперь осталось на Алгол 60 переписать. Хочется иметь простую интерактивную игрушку на Алголе в качестве демо.

Для математиков: в этой статье имеется серьёзная теоретическая проработка.
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org