guess_my_rule
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
guess_my_rule [2020/05/30 15:50] – frchris | guess_my_rule [2022/08/03 12:02] – [Guess My Integer Rule] frchris | ||
---|---|---|---|
Line 4: | Line 4: | ||
For example, The secret rule might be that it is an integer that is a prime number. The rule-maker Starts with "2 follows my rule, but 4 does not" | For example, The secret rule might be that it is an integer that is a prime number. The rule-maker Starts with "2 follows my rule, but 4 does not" | ||
- | In our computer version, the user is given clues, asking | + | In our computer version, the user asks about a certain '' |
+ | |||
+ | To be fair, the secret rule cannot involve any random behavior. | ||
==== Guess My Integer Rule==== | ==== Guess My Integer Rule==== | ||
+ | This is best used with the BlueJ IDE where you can make an instance of a class without writing a '' | ||
+ | < | ||
+ | * Make up your own rule | ||
+ | | ||
+ | * @author Chris Thiel, OFMCap | ||
+ | * | ||
+ | */ | ||
+ | public class GuessMyIntegerRule | ||
+ | { | ||
+ | private String secretRule = "It must be prime"; | ||
+ | public boolean DoesThisIntFollowMyRule(int n) | ||
+ | { | ||
+ | for(int i = 2; i < n; i++) | ||
+ | if (n % i == 0) | ||
+ | return false; | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | public String IGiveUp() | ||
+ | { | ||
+ | return secretRule; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
==== Guess My String Rule ==== | ==== Guess My String Rule ==== | ||
guess_my_rule.txt · Last modified: 2022/08/11 10:09 by frchris