On a sheet of paper, the players each write a 4-digit secret number.
The digits must be all different. Then, in turn, the players try to guess their opponent's number who
gives the number of matches. If the matching digits are in their right positions, they are "bulls",
if in different positions, they are "cows".
Example: Secret number: 4271 Opponent's try: 1234
Answer: 1 bull and 2 cows. (The bull is "2", the cows are "4" and "1".)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
@question = Question.new(question_params) | |
respond_to do |format| | |
if @question.save | |
format.html { redirect_to @question, notice: "Question was successfully created." } | |
format.json { render :show, status: :created, location: @question } | |
else | |
format.html { render :new, status: :unprocessable_entity } | |
format.json { render json: @question.errors, status: :unprocessable_entity } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
int resultFindNthSmallest; | |
int resultsumOf; | |
int resultPersistance; | |
resultFindNthSmallest = findNthSmallest([6, 2, 9, 1], 2); | |
print("findNthSmallest([6, 2, 9, 1], 2) =$resultFindNthSmallest"); | |
resultFindNthSmallest = | |
findNthSmallest([57, 3, 0, -5, 2, 67, 32, 9, 1, 2], 5); | |
print( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
int resultFindNthSmallest; | |
resultFindNthSmallest = findNthSmallest([6, 2, 9, 1], 2); | |
print("findNthSmallest([6, 2, 9, 1], 2) =$resultFindNthSmallest"); | |
resultFindNthSmallest = | |
findNthSmallest([57, 3, 0, -5, 2, 67, 32, 9, 1, 2], 5); | |
print( | |
"findNthSmallest([57, 3, 0, -5, 2, 67, 32, 9, 1, 2], 5) = $resultFindNthSmallest"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
int resultsumOf; | |
resultsumOf = sumOf([9, 34, -23, 0, 4, 8,1]); | |
print("sumOf([9, 34, -23, 0, 4, 8,1]) =$resultsumOf"); | |
resultsumOf = sumOf([901, 492, -10223, 3791, 243, 2]); | |
print("sumOf([901, 492, -10223, 3791, 243, 2]) =$resultsumOf"); | |
} | |
int sumOf(List<int> integers) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
int resultPersistance; | |
resultPersistance = multiplicativePersistenceOf(489); | |
print("multiplicativePersistenceOf(489) =$resultPersistance"); | |
resultPersistance = multiplicativePersistenceOf(912); | |
print("multiplicativePersistenceOf(912) =$resultPersistance"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fizz_buzz(n) | |
if n % 10 == 0 | |
"FizzBuzz" | |
elsif n % 5 == 0 | |
"Buzz" | |
elsif n % 2 == 0 | |
"Fizz" | |
else | |
n | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fizz_buzz(n): | |
if n % 10 == 0 : | |
return "FizzBuzz" | |
elif n % 5 == 0: | |
return "Buzz" | |
elif n % 2 == 0: | |
return "Fizz" | |
else: | |
return n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
for(i=0; i<20;i++){ | |
print(fizz_buzz(i)); | |
} | |
} | |
String fizzBuzz() { | |
if (i % 3 == 0 && i % 5 == 0) { | |
return "FizzBuzz"; | |
} else if (i % 3 == 0) { |
OlderNewer