Быки и коровы
2024-08-31 14:30![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
В качестве субботнего развлечения сваял простейшую игру "быки и коровы" на Си. На самом деле перепёр с Бейсика. Исходник здесь: bulls-and-cows.c. Сыграем:
Для математиков: в этой статье имеется серьёзная теоретическая проработка.
$ cc -O bulls-and-cows.c -o bulls-and-cowsСамому думать лень, проще задействовать решатель из интернета: kuniga.me/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.
Теперь осталось на Алгол 60 переписать. Хочется иметь простую интерактивную игрушку на Алголе в качестве демо.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]
Для математиков: в этой статье имеется серьёзная теоретическая проработка.