annotate 1-Ruby/day1.rb @ 97:85a5e9a6ef5c

Add more notes on extracting Just/Maybe values
author IBBoard <dev@ibboard.co.uk>
date Sun, 30 Jun 2019 16:09:44 +0100
parents 3e4ea3d47880
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 #! /usr/bin/env ruby
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 puts 'Hello, World'
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 puts 'Hello, Ruby'.index('Ruby')
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 i = 1
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 while i <= 10
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 puts "This is sentence number #{i}"
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 i = i + 1
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 end
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 randNum = rand(10)
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 guess = 11
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 until guess == 'q' or guess.to_i == randNum
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 puts 'Guess the number (0-9) or "q" to quit'
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 guess = gets.strip
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 end
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19
3e4ea3d47880 Add day 1 exercises
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 puts "Well done! The number was #{randNum}" unless guess == 'q'