changeset 13:3e4ea3d47880

Add day 1 exercises
author IBBoard <dev@ibboard.co.uk>
date Tue, 03 Jan 2017 20:10:57 +0000
parents e5b84cc7bc29
children 9aa1eba404f0
files 1-Ruby/day1-irb.output 1-Ruby/day1-ruby.output 1-Ruby/day1.rb
diffstat 3 files changed, 88 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/1-Ruby/day1-irb.output	Tue Jan 03 20:10:57 2017 +0000
@@ -0,0 +1,48 @@
+day1.rb(main):001:0> #! /usr/bin/env ruby
+day1.rb(main):002:0* 
+day1.rb(main):003:0* puts 'Hello, World'
+Hello, World
+=> nil
+day1.rb(main):004:0> puts 'Hello, Ruby'.index('Ruby')
+7
+=> nil
+day1.rb(main):005:0> i = 1
+=> 1
+day1.rb(main):006:0> 
+day1.rb(main):007:0* while i <= 10
+day1.rb(main):008:1> 	puts "This is sentence number #{i}"
+day1.rb(main):009:1> 	i = i + 1
+day1.rb(main):010:1> end
+This is sentence number 1
+This is sentence number 2
+This is sentence number 3
+This is sentence number 4
+This is sentence number 5
+This is sentence number 6
+This is sentence number 7
+This is sentence number 8
+This is sentence number 9
+This is sentence number 10
+=> nil
+day1.rb(main):011:0> 
+day1.rb(main):012:0* 
+day1.rb(main):013:0* randNum = rand(10)
+=> 3
+day1.rb(main):014:0> guess = 11
+=> 11
+day1.rb(main):015:0> until guess == 'q' or guess.to_i == randNum
+day1.rb(main):016:1> 	puts 'Guess the number (0-9) or "q" to quit'
+day1.rb(main):017:1> 	guess = gets.strip
+day1.rb(main):018:1> end
+Guess the number (0-9) or "q" to quit
+Guess the number (0-9) or "q" to quit
+Guess the number (0-9) or "q" to quit
+Guess the number (0-9) or "q" to quit
+Guess the number (0-9) or "q" to quit
+Guess the number (0-9) or "q" to quit
+=> nil
+day1.rb(main):019:0> 
+day1.rb(main):020:0* puts "Well done! The number was #{randNum}" unless guess == 'q'day1.rb(main):020:0* 
+day1.rb(main):020:0> 
+Well done! The number was 3
+=> nil
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/1-Ruby/day1-ruby.output	Tue Jan 03 20:10:57 2017 +0000
@@ -0,0 +1,20 @@
+Hello, World
+7
+This is sentence number 1
+This is sentence number 2
+This is sentence number 3
+This is sentence number 4
+This is sentence number 5
+This is sentence number 6
+This is sentence number 7
+This is sentence number 8
+This is sentence number 9
+This is sentence number 10
+Guess the number (0-9) or "q" to quit
+Guess the number (0-9) or "q" to quit
+Guess the number (0-9) or "q" to quit
+Guess the number (0-9) or "q" to quit
+Guess the number (0-9) or "q" to quit
+Guess the number (0-9) or "q" to quit
+Guess the number (0-9) or "q" to quit
+Well done! The number was 7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/1-Ruby/day1.rb	Tue Jan 03 20:10:57 2017 +0000
@@ -0,0 +1,20 @@
+#! /usr/bin/env ruby
+
+puts 'Hello, World'
+puts 'Hello, Ruby'.index('Ruby')
+i = 1
+
+while i <= 10
+	puts "This is sentence number #{i}"
+	i = i + 1
+end
+
+
+randNum = rand(10)
+guess = 11
+until guess == 'q' or guess.to_i == randNum
+	puts 'Guess the number (0-9) or "q" to quit'
+	guess = gets.strip
+end
+
+puts "Well done! The number was #{randNum}" unless guess == 'q'
\ No newline at end of file