Created
September 4, 2014 04:47
-
-
Save cocolote/8374fd01c7d218eb06d4 to your computer and use it in GitHub Desktop.
Exercises for App Academy
This file contains hidden or 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
AppAcademy |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="RUBY_MODULE" version="4"> | |
<component name="NewModuleRootManager"> | |
<content url="file://$MODULE_DIR$" /> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
</component> | |
</module> | |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" /> | |
</project> | |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectRootManager" version="2" project-jdk-name="ruby-1.9.3-p545" project-jdk-type="RUBY_SDK" /> | |
</project> | |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/.idea/AppAcademy.iml" filepath="$PROJECT_DIR$/.idea/AppAcademy.iml" /> | |
</modules> | |
</component> | |
</project> | |
This file contains hidden or 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
<component name="DependencyValidationManager"> | |
<state> | |
<option name="SKIP_IMPORT_STATEMENTS" value="false" /> | |
</state> | |
</component> |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="VcsDirectoryMappings"> | |
<mapping directory="" vcs="" /> | |
</component> | |
</project> | |
This file contains hidden or 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 is_prime?(num) | |
i = 2 | |
while i < num | |
if num % i == 0 | |
return false | |
end | |
i += 1 | |
end | |
true | |
end | |
def primes(max) | |
i = 1 | |
prime_arr = [] | |
while i < max | |
prime_arr << i if is_prime?(i) | |
i += 1 | |
end | |
prime_arr.each {|prime| print "#{prime}, "} | |
end | |
print 'Enter a number:' | |
max = Integer(gets.chomp) | |
primes(max) |
This file contains hidden or 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
puts "Let's see if the number is prime or not" | |
print 'Enter a number to analyze:' | |
n = Integer(gets.chomp) | |
def is_prime?(num) | |
i = 2 | |
while i < num | |
if num % i == 0 | |
return puts 'false' | |
end | |
i += 1 | |
end | |
return puts 'true' | |
end | |
is_prime?(n) |
This file contains hidden or 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
print 'Enter a number (base):' | |
n1 = Integer(gets.chop) | |
print 'Enter another number (exponent):' | |
n2 = Integer(gets.chomp) | |
def pow(base, expo) | |
return puts "it has to be positive numbers" if (base <= 0 || expo <= 0) | |
result = 1 | |
expo.times do | |
result = result*base | |
end | |
puts "The result is #{result}" | |
end | |
pow(n1, n2) |
This file contains hidden or 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 sum(an) | |
result = 0 | |
an.each do |num| | |
result = result + num | |
end | |
puts "The result is #{result}" | |
end | |
nums = [2,4,6,8,2,8,125,-32,2,0,0] | |
sum(nums) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment