Doing some silly stuff with kiddos[0]
This commit is contained in:
parent
d548740ed0
commit
3b7bbd5ff1
38
kiddofun/quiz.rb
Normal file
38
kiddofun/quiz.rb
Normal file
@ -0,0 +1,38 @@
|
||||
def main
|
||||
loop do
|
||||
secret_number = rand(0..99)
|
||||
hint_0 = secret_number - rand(0..49)
|
||||
|
||||
loop do
|
||||
say "#{secret_number - hint_0} + #{hint_0} is", newline: false
|
||||
print '?: '
|
||||
begin
|
||||
answer = Integer($stdin.readline.strip)
|
||||
if answer == secret_number
|
||||
say 'You got it!'
|
||||
break
|
||||
else
|
||||
say 'That is so incorrect!'
|
||||
end
|
||||
rescue => e
|
||||
$stderr.puts e
|
||||
say 'NO, Human!'
|
||||
end
|
||||
end
|
||||
|
||||
say 'Do you want to play again? ', newline: false
|
||||
print '[Y/n] '
|
||||
if $stdin.readline.strip.downcase =~ /^n/
|
||||
say 'Goodbye, Human!'
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def say(msg, newline: true)
|
||||
print msg
|
||||
print "\n" if newline
|
||||
system "say -v ralph #{msg.inspect}"
|
||||
end
|
||||
|
||||
main
|
13
kiddofun/rounding.go
Normal file
13
kiddofun/rounding.go
Normal file
@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
number := 43
|
||||
|
||||
fmt.Printf("%-2d - number\n", number)
|
||||
fmt.Printf("%-2d - number tens place\n", number/10)
|
||||
fmt.Printf("%-2d - number tens place multiplied by 10\n", (number/10)*10)
|
||||
}
|
9
kiddofun/rounding.rb
Normal file
9
kiddofun/rounding.rb
Normal file
@ -0,0 +1,9 @@
|
||||
number = Integer(ARGV.fetch(0))
|
||||
divisor = Float(ARGV.fetch(1, 10.0))
|
||||
|
||||
raise 'Invalid divisor' unless divisor % 10 == 0
|
||||
|
||||
puts "#{number} - number"
|
||||
puts "#{(Float(number) / divisor).round(0)} - number divided by #{divisor}"
|
||||
puts "#{(Float(number) / divisor).round(0) * Integer(divisor)} - " \
|
||||
"number divided by #{divisor}, multiplied by #{Integer(divisor)}"
|
Loading…
Reference in New Issue
Block a user