Git Product home page Git Product logo

learn_to_program's Introduction

Learn To Program

##Ruby Week

Now that you have completed the first week of the PreCourse and need to continue developing your Ruby skills, we recommend that you continue with Chris Pine's Learn To Program book 2nd Edition. Please complete chapters 9-14.

Please attempt every exercise, submitting the code to us using your newfound git and GitHub skils by forking https://github.com/makersacademy/learn_to_program, and submitting a pull request (Note that submitting a pull request will kick off some Continuous Integration <-- see link for more details).

Do not spend more than an hour on any individual exercise. The solutions are included at the end of the book. This week it is better that you cover all the chapters, and review the solutions for any exercises that you cannot complete in under an hour. Please do not look at any individual solution until you have at least tried each individual exercise.

###Setup Instructions

  • Fork the repo to your own
  • Push to your own fork (check the upstream)
  • Open a pull request straight away
  • Commit and push your code after each challenge so the CI server can check your work as you go along.
  • You must get a green tick at the end of the exercise from the CI to pass the week's challenge.

###For submitting exercises from the Chris Pine Learn to Program Book

If you would like to run the tests associated with each chapter or even individual exercies you can do so as follows. We use the RSpec library to test the code is working properly. The RSpec library is available as a Ruby 'gem', which you can install in your computer by typing the following at the command line prompt:

$ gem install rspec

Once you have RSpec installed as above, ensure that you have navigated to the root directory of this learn_to_program repo, e.g.

cd /Users/JohnDoe/Projects/MakersAcademy/learn_to_program

Then if you'd like to check, say, your solution for the chapter 9 'ask' program you can run the following command:

rspec spec/ch09/ask_spec.rb

You might find the output of the command a little difficult to interpret, but in general the output will have a green colour when the test is passing, and a red colour when some part of the test is failing. At this stage it is not necessary for you to understand how RSpec works, or even be able to make all the tests pass. We just provide these notes in case you are interested in running the tests locally.

If you are curious feel free to inspect the contents of files like spec/ch09/ask_spec.rb - the contents are pure Ruby, but they use parts of the RSpec library that will make them look very unfamiliar. You'll be covering RSpec in some detail in the week 1 of the main Makers Academy course, so if this all seems to complicated, just leave it for now, and focus on your best effort to write the code for the Learn to Program exercises.

If you are keen to explore more of the tests and would like to run more than one at a time please use the following commands:

rspec spec/ch09/

will run all the tests for the chapter 9 exercises (that have tests) and

rspec spec/ch10/

will run all the ch10 tests and so on. If you want to run every single test at once you can run:

rspec

but be prepared for potentially quite a lot of output! :-)

learn_to_program's People

Contributors

anitacanita avatar kevinpmcc avatar nikeshashar avatar tansaku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learn_to_program's Issues

Can't push anything to github

I have forked and pulled the repository. Adding and committing to git seems to work, but every time I try to push it it comes up with:
"fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
git remote add
and then push using the remote name
git push "
When I try to specify where it's going it keeps coming up with errors. I think I may be formatting the url to push to wrong but I can't work out where. I haven't had this issue before when pushing to github.

spec/ch14/better_program_logger_spec.rb indentation issue

Hello

on the chapter 14 exercise rspec "/better_program_logger_spec.rb" I think there is an issue with teh rspec test and the STDOUT that gets sent to the test.

I get

expected: ("Beginning \"outer block\"...")
              got: ("   Beginning \"outer block\"...") 

for failure however if I run my method using the same blocks you have used in the rspec I get the below:

Beginning "outer block"...

So there are 3 spaces before the "Beginning" on the rspec results but none on my actual results when I run on the shell or in sublime.

my code is here for the logger. If the problem is with my code I will happily re-write but I think this may be an issue with the return the rspec is getting from the STDOUT.

Thanks

Lewis

Ch9 - Old school roman numerals exercise

I am stuck on this exercise because I do not understand how the following code works:

roman << 'M' * (num / 1000)

roman << 'D' * (num % 1000/500)

roman << 'C' * (num % 500/100)

roman << 'L' * (num % 100/50)

roman << 'X' * (num % 50/10)

roman << 'V' * (num % 10/5)

roman << 'I' * (num % 5/1)

I am trying to work out manually how the (num % 100/50) section of the program works. It works when I put the values in the program and run them and provides the correct answer. However when I try working it out on paper I keep getting 0 as the remainders (from the %).

For example if 30 was the number i'm using:

30 % 100/50 --> 30 % 2 --> 15 remainder 0?

What am I doing wrong here?

Travis checks failed, even though program works

#477

There is the repo. Locally, it works, but travis CI says it does not. I think I have my output in a slightly different format to what it is expecting, as I know it works when I try the program from terminal. Does this 100% need to work, or should I move on?

I can't seem to run any of the rspec tests on my CL

#487

I am putting in the correct command on the command line but it won't run the rspec checks.
Here is what it is giving me:
Felixs-Air:learn_to_program felixharrison$ rspec ./spec/ch10 /Users/felixharrison/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:inload': /Users/felixharrison/Projects/learn_to_program/ch10-nothing-new/english_number.rb:84: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)`

What have I done wrong.

PS sorry for the long code

rspec test says it gets nil

screen shot 2015-09-22 at 19 34 13

Hi,

My code works, but every time I run the test it comes back failed, any idea why? (I've checked file names and don't run anything outside the method)

Cheers

Ch13 - orange_tree.rb

Hi guys,

I'm having a lot of trouble getting this one to pass. I even tried using the solution code as-is and it still doesn't work. Here's the error:

Emmas-MacBook-Air:learn_to_program emmabeynon$ rspec spec/ch13/orange_tree_spec.rb

OrangeTree
  reports height and number of oranges (FAILED - 1)

Failures:

  1) OrangeTree reports height and number of oranges
     Failure/Error: expect(ot.one_year_passes).to eq 'This year your tree grew to 10.0m tall, and produced 125 oranges.'

       expected: "This year your tree grew to 10.0m tall, and produced 125 oranges."
            got: "Oh, no! The tree is too old, and has died. :("

       (compared using ==)
     # /Users/emmabeynon/Dropbox (Personal)/Makers_Academy/Projects/learn_to_program/spec/ch13/orange_tree_spec.rb:16:in `block (2 levels) in <top (required)>'

Finished in 0.01465 seconds (files took 0.19631 seconds to load)
1 example, 1 failure

Failed examples:

rspec /Users/emmabeynon/Dropbox (Personal)/Makers_Academy/Projects/learn_to_program/spec/ch13/orange_tree_spec.rb:12 # OrangeTree reports height and number of oranges

Ch_10 shuffle.rb passes my test but dfails in CI

Hi, with reference to the attached screen shot the shuffle method passes my simple test on line 25 but the shuffle method fails CI test after I submit a pull request.

Can anyone spot anything wrong with my shuffle method?

screen shot 2015-09-23 at 22 21 23

ninety_nine_bottles_of_beer_spec.rb issue

After my prev issue I'm running the rspecs from the right place. However I get the same 0 examples, 0 failures with ninety_nine_bottles_of_beer.

Had a look inside the file and below were the contents:

describe 'ninety nine bottles of beer' do

it doesn't look right compared to the others as they has a ``require './ch10-nothing-new/.rb'` to the ruby in question then a test script

Travis CI build failed to load command: rspec

Hey guys, I've gone through all the challenges for wk 3 but can't get CI to pass - the build fails before rspec even runs so it's not checking my answers... any ideas? I know it's not essential to pass the CI build, but something inside me really wants that little green tick...

bundler: failed to load command: rspec (/home/travis/build/makersacademy/learn_to_program/vendor/bundle/ruby/2.2.0/bin/rspec)

You can hopefully see the issue I'm having here:
https://travis-ci.org/makersacademy/learn_to_program/builds/130508506

I haven't changed any of the Gemlock files or anything. I played around with the version number in travis.yml but that didn't work either so I've changed it back.

Cheers!

Ch11. Trying to make a method to check whether or not a batch has already been used

I've written a method that, to my understanding, checks whether or not the current working directory has any files starting with the current batch name followed by any number of digits and then a .JPG/.jpg.

I think its the regex /\d+/, i want that to mean any numbers.

I've looked on a lot of different websites but I must be missing something to make it work..

Method runs and doesn't through up any errors but also doesnt actually work as the program goes on to overwrite files already in the directory. Code dump below:

def batch_name bname

  if File.exist?("#{bname}#{/\d+/}.{JPG,jpg}")
    puts "Error. A batch already exists with this name.\n
    Please choose another name for this batch."
    batch_name gets.chomp
  else
    bname
  end

end

ch14 program_logger Rspec expectiation

Very minor typo issues that I thought I'd raise here for feedback on ch14's exercises:

Rspec expects methods called "program_log" and "better_log", whereas the exercise skeletons both contain methods just called "log" instead.

For program_log, Rspec also expects the return values of "5" and "I like Thai food!" to be on the same line as "{block desc} finished, returning: " (i.e. just to the right of "returning"), whereas the Chris Pine output has these return values coming on the following line.

Typo preventing rspec from working properly in Ch09

Please fix the following bug:

The test file for the "roman numerals" challenge in Ch09 in the Learn to Program repo has a typo -- the filename is roman_numeral_spec.rb, but the challenge file is roman_numerals.rb (note pluralization).

Thank you.

safer_picture issue!

Hi there!

I have a little problem..
I built this code.. the target is change the name of the jpg file in my folder.. I does not work.. I thought it might not be pointing at the folder.. its that way I added the block creating a txt file, the point is that the code create the file, which means is pointing at the folder.. however..the problem is either not pointing at the jpg files or the block code does not work.. I think is not pointing at the files because the downloading files does not increase the counter..
info: the folder has three jpg files, therefore.. the each do should print three times the art into the files.. but it only writes once "asasasasaaasasasaasasasasasasasaa'"

what do you think?

thank you!

Dir.chdir'/Users/sorry/desktop/photos'
pic_names = Dir['Users/sorry/desktop/photos/*/.jpg']

require 'yaml'

test_arr= ['asasasasaaasasasaasasasasasasasaa']

test_arr = test_arr.to_yaml
filename='prueba.txt'

File.open filename, 'w' do |x|
x.write test_arr
end

pic_names.each do |a|
prints 'asdadadada'
end

the block above demostrate its pointing at the folder..

the block bellow

puts 'How would you like to name your photos?'
newname = gets.chomp

puts
print "Downloading #{pic_names.length} photos: "

pic_number = 1
pic_names.each do |x|
print '.'

new_name = if pic_number < 10
"#{name}0 #{pic_number}.jpg"
else
"#{name} #{pic_number}.jpg"
end
File.rename name, newname
pic_number = pic_number + 1
end

multiple pull requests

Hi,

When I finished the exercises for chapter 9 I created a pull request. Now that I've finished chapter 10, I could not create another one but I saw that the new commits were included in the original pull request. Am I right in thinking that I can just update the pull request or is there a way to create a new one?

Thanks,
Giuseppe

Codewars Problem - Method evaluating to nil

Coming to the end of a really beasty beta kata on codewars (https://www.codewars.com/kata/57b2fc418491f9f092000029/train/ruby ).

Essentially it is about deciphering a coded text based on a number of cyphers contained in hashes, as well as somme additional rules that need to be accounted for.

As part of the additional rules, I've created some statements to evaluate for these rules / exceptions. These for the most part work, apart from one which is supposed to take into account the awkwardly worded 'characters different than a letter' which may or may not follow a character..

After some googling I managed to steal someone else's code (that's allowed right, ?! ^-^), using a regex statement - see below. A nearly identical statement is used to evaluate whether the character being evaluated is a number (0-9). However, for the one shown I am getting an

'undefined method `[]' for nil:NilClass (NoMethodError)'.

I assume this means that the statement is evaluating to nil and the script doesn't know what to do in this case. My question therefore is thus:

  1. Why does it evaluate to nil , as opposed to false?
  2. How do I get around it!?

Any guidance / sympathy is much appreciated! Also this is my first issue so if I've worded it poorly / clumsily and you have any pointers than equally helpful! This is the last thing I need to pass the kata and I neeeeeed these points!

Cheers
screen shot 2016-09-10 at 14 35 56

Orange_tree

Does anybody know why my code doesn't pass the rspec test?

class OrangeTree
def initialize
@Age = 0
@height = 1
@orange_count = 0
@alive = true
puts "A new orange tree is growing!"
end

def height
    @height
end
def one_year_passes

    if @age >= 10
        return die
    else
        @age += 1
        @height += 1
        @orange_count = 0
    end

    puts "one year passes. The tree is  #{@age} years old, and its #{height} meters tall"
    puts ""
    if @age > 4
        count_the_oranges
    end
end

def count_the_oranges
    @orange_count = 2 * @age
    if @alive
        puts "The tree produces #{@orange_count} oranges"
        puts "-------------------"
    else
        puts "The tree's dead and has no oranges"
    end
end

def pick_an_orange
    if @orange_count > 0
        @orange_count -= 1
        puts "We picked one orange. It was delicious! The tree now has #{@orange_count} oranges"
    else
        puts "There are no more oranges!"
    end
end

def die
    @alive = false
    puts "The orange tree has died :("

end

end

x = OrangeTree.new
x.one_year_passes
x.one_year_passes
x.one_year_passes
x.one_year_passes
x.one_year_passes
x.one_year_passes
x.one_year_passes
x.one_year_passes
x.one_year_passes
x.one_year_passes
x.one_year_passes
x.one_year_passes
x.count_the_oranges
x.count_the_oranges
x.count_the_oranges

x.count_the_oranges

puts "**************"

x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange
x.pick_an_orange

Problems Submitting old_roman_numerals

Hi, I have a problem with old_roman_numerals submission. I believe my code is ok, however, irb says that I have undefined local variable error. Since I could not find a problem in my code I tried to open challenge solution file with irb (where code is Definitely correct) and it still shows the same undefined local variable error.

screen3

I tried to submit my code with Travis CI and it doesn't pass as well:

screen4

This is my code :

screen5

Can anyone tell me what is wrong with my code/irb/or Travis CI submission?

Thank you!

Tests not passing for Modern Roman Numbals

Here is my code:

def roman_numeral num
+    roman = ''
+    roman = roman + 'M' * (num / 1000)
+    roman = roman + 'D' * (num % 1000 / 500)
+    roman = roman + 'C' * (num % 500 / 100)
+    roman = roman + 'L' * (num % 100 / 50)
+    roman = roman + 'X' * (num % 50 / 10)
+    roman = roman + 'V' * (num % 10 / 5)
+    roman = roman + 'I' * (num % 5 / 1)
+    roman
+end
+
+number = roman_numeral(54)
+
+if number.include? 'VIIII'
+   puts number.gsub!('VIIII', 'IX')
+elsif number.include? 'IIII'
+   puts number.gsub!('IIII', 'IV')
+else
+   puts number
+end
+

+# 16) roman numerals translates 519 to DXIX
+# Failure/Error: expect(roman_numeral(i+500)).to eq numeral
+
+# expected: "DXIX"
+# got: "DXVIIII"

when I do number = roman_numeral(519)

I get DXIX but still doesnt pass. this is the same for others but looks fine to me?

extend_built_in_classes.rb fails test on more extensive test of roman numerals

Can't get my head around this one.

I have copied across my roman_numerals.rb solution into extend_built_in_classes.rb like this:

def to_roman
    roman = ''
    num = self

    ...

    if num % 10 == 9
      roman += 'IX'  
    else
      roman += 'V' * (num % 10 / 5)    
      if num % 5 == 4
        roman += 'IV'
      else
        roman += 'I' * (num % 5)
      end   
    end

    roman

end


It works fine in irb, with 4.to_roman giving IV, 9.to_roman giving IX etc.

But for some reason it is failing on Travis CI:

more extensive test of roman conversion
    translates 1 to I
    translates 2 to II
    translates 3 to III
    translates 4 to IIII (FAILED - 1)
    translates 5 to V
    translates 6 to VI
    translates 7 to VII
    translates 8 to VIII
    translates 9 to VIIII (FAILED - 2)

Anyone got any ideas? The original roman_numerals.rb passes in full.

Running ch13 orange tree spec

Hi guys,

I have been doing the ch13 orange tree challenge from CP's learn to program and have been testing my code with the rspec file as I went along and it was working fine.
Now that I have got my code to work (I have been testing it with https://repl.it/languages/ruby and in there it works absolutely fine), when I run the rspec test it goes into a weird mode where I can type things. I have to press ctrl + c to abort and then says "RSpec is shutting down and will print the summary report... Interrupt again to force quit."
I then press ctrl + c again and it quits it.
I tested a previous version of code I wrote and it works absolutely fine, however when I run the code that I know will work, it goes into that weird mode. I have added a screenshot here:
screen shot 2016-02-19 at 15 30 01
Can anyone help me with why this is happening?

This is my code that I am testing:
class OrangeTree

your code here

def initialize
@height = 0
@orange_count = 0
@alive = true
end

def one_year_passes
while @alive
if @height > 10.0
@alive = false
return "Oh, no! The tree is too old, and has died. :("

  elsif @height.round(2) <= 10.0
    @height += 0.4
    if @height > 2.0
      @orange_count += 6.27
    end

    return "This year your tree grew to #{@height.round(2)}m tall, and produced #{@orange_count.floor} oranges."
  end
end

return "A year later, the tree is still dead. :("

end

def height
while @alive
@height.round(2)
end
return "A dead tree is not very tall. :("
end

def count_the_oranges
while @alive
@orange_count.floor
end
return "A dead tree has no oranges. :("
end

def pick_an_orange
while @alive
@orange_count -= 1
puts "You picked an orange and it was delicious."
end
return "A dead tree has no oranges to pick. :("
end

end

ch10 shuffle

rspec returns FAILED, tried different methods even tried Ruby's shuffle. Keeps giving me error on 'maintains all elements'. can't find what could be wrong

Ch09. Continuous Integration test fail despite RSpec pass: roman numerals code (ch09 L2P) passes RSpec tests but fails CI

rspe_ci_issue
On the work completed for ch09 in Learn-to-Program (as forked from Makers repository) I have come up with working solutions for all three exercises in the chapter. On testing locally with RSpec the code passes all tests (see screenshots). However, once pushed to my GitHup L2P forked repo, the code does not pass the CI integration test. If a new pull request is attempted the CI test is still not passed.

Find below the link to CI results page for the ch09 L2P:

master...AppsDJ:master

#370

L2P forked repo for roman-numerals link:

https://github.com/AppsDJ/learn_to_program/blob/master/ch09-writing-your-own-methods/roman_numerals.rb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.