Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allergies #23

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7b775c8
gigasecond program
mayur-kambariya Jan 11, 2017
2ac4569
gigasecond program
mayur-kambariya Jan 11, 2017
8fcd19d
Update Comment code Gigasecond
mayur-kambariya Jan 12, 2017
58d392b
rna Transcription Upload 1
mayur-kambariya Jan 12, 2017
f9116be
Update rna_transcription 2
mayur-kambariya Jan 12, 2017
0a0bbe8
raindrops upload succefully 1
mayur-kambariya Jan 12, 2017
a6c9790
Difference of squares is upload 1
mayur-kambariya Jan 12, 2017
4773c7c
this pangram program using .each loop
mayur-kambariya Jan 12, 2017
bb87e42
Roman Numerals Uploaded succefully
mayur-kambariya Jan 13, 2017
2990202
Binary Digit convert into Decimal number 1
mayur-kambariya Jan 13, 2017
6ffa5bb
phone Number upload ok 1
mayur-kambariya Jan 13, 2017
75d3630
Roman numerals in short logic program second
mayur-kambariya Jan 16, 2017
f6a72ee
Roman numerals in short logic program second
mayur-kambariya Jan 16, 2017
70e859f
Space age Problem first
mayur-kambariya Jan 16, 2017
18d67fa
Rail fence cipher uploaded
mayur-kambariya Jan 16, 2017
63823ec
Hexadecimal Convert to Decimal number 1
mayur-kambariya Jan 17, 2017
8c4b22c
Queen attack Check 1
mayur-kambariya Jan 17, 2017
8b355f5
Atbash cipher is uploaded 1
mayur-kambariya Jan 17, 2017
eabfa8b
String convert into Maths equation successfull 1
mayur-kambariya Jan 18, 2017
fb7389d
largest series product find inside given string
mayur-kambariya Jan 18, 2017
b0637af
pascals triangle uploaded
mayur-kambariya Jan 18, 2017
8601653
isogram return letter is or not
mayur-kambariya Jan 19, 2017
412471b
ETL Commit Successfully 1
mayur-kambariya Jan 20, 2017
6072c09
Sum of Multiples is uploaded 1
mayur-kambariya Jan 20, 2017
e0ed246
binary number update 2
mayur-kambariya Jan 20, 2017
41cfb29
clock time without dates
mayur-kambariya Jan 20, 2017
0b7b184
allergiries problem uploaded 1
mayur-kambariya Jan 23, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions allergies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Allergies

Write a program that, given a person's allergy score, can tell them whether or not they're allergic to a given item, and their full list of allergies.

An allergy test produces a single numeric score which contains the
information about all the allergies the person has (that they were
tested for).

The list of items (and their value) that were tested are:

* eggs (1)
* peanuts (2)
* shellfish (4)
* strawberries (8)
* tomatoes (16)
* chocolate (32)
* pollen (64)
* cats (128)

So if Tom is allergic to peanuts and chocolate, he gets a score of 34.

Now, given just that score of 34, your program should be able to say:

- Whether Tom is allergic to any one of those allergens listed above.
- All the allergens Tom is allergic to.

Note: a given score may include allergens **not** listed above (i.e.
allergens that score 256, 512, 1024, etc.). Your program should
ignore those components of the score. For example, if the allergy
score is 257, your program should only report the eggs (1) allergy.


* * * *

For installation and learning resources, refer to the
[exercism help page](http://exercism.io/languages/ruby).

For running the tests provided, you will need the Minitest gem. Open a
terminal window and run the following command to install minitest:

gem install minitest

If you would like color output, you can `require 'minitest/pride'` in
the test file, or note the alternative instruction, below, for running
the test file.

In order to run the test, you can run the test file from the exercise
directory. For example, if the test suite is called
`hello_world_test.rb`, you can run the following command:

ruby hello_world_test.rb

To include color from the command line:

ruby -r minitest/pride hello_world_test.rb

The test files may have the execution bit set so you may also be able to
run it like this:

./hello_world_test.rb

## Source

Jumpstart Lab Warm-up [http://jumpstartlab.com](http://jumpstartlab.com)

## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

41 changes: 41 additions & 0 deletions allergies/allergies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Allergies
def initialize(allergies_number)

@allergy_score = {
cats: 128 ,
pollen: 64 ,
chocolate: 32 ,
tomatoes: 16 ,
strawberries: 8 ,
shellfish: 4 ,
peanuts: 2 ,
eggs: 1
}
allergies_number -=256 if allergies_number > 256
calculate_allergy(allergies_number)
end

def calculate_allergy(number)
@store_allergy = []
@allergy_score.each do |key,value|
if value.to_i <= number
number -= value.to_i
@store_allergy << key.to_s
end
end
end

def allergic_to?(allergies_string)
@store_allergy.include?(allergies_string)
end

def list
@store_allergy.reverse
end
end
# all = Allergies.new(8)
# all.allergic_to?("strawberries")
# all = Allergies.new(5)
# all.allergic_to?("strawberries")
# all = Allergies.new(509)

72 changes: 72 additions & 0 deletions allergies/allergies_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env ruby
gem 'minitest', '>= 5.0.0'
require 'minitest/autorun'
require_relative 'allergies'

class AllergiesTest < Minitest::Test
def test_no_allergies_means_not_allergic
allergies = Allergies.new(0)
refute allergies.allergic_to?('peanuts')
refute allergies.allergic_to?('cats')
refute allergies.allergic_to?('strawberries')
end

def test_is_allergic_to_eggs
# skip
allergies = Allergies.new(1)
assert allergies.allergic_to?('eggs')
end

def test_allergic_to_eggs_in_addition_to_other_stuff
# skip
allergies = Allergies.new(5)
assert allergies.allergic_to?('eggs')
assert allergies.allergic_to?('shellfish')
refute allergies.allergic_to?('strawberries')
end

def test_no_allergies_at_all
# skip
allergies = Allergies.new(0)
assert_equal [], allergies.list
end

def test_allergic_to_just_eggs
# skip
allergies = Allergies.new(1)
assert_equal ['eggs'], allergies.list
end

def test_allergic_to_just_peanuts
# skip
allergies = Allergies.new(2)
assert_equal ['peanuts'], allergies.list
end

def test_allergic_to_eggs_and_peanuts
# skip
allergies = Allergies.new(3)
assert_equal %w(eggs peanuts), allergies.list
end

def test_allergic_to_lots_of_stuff
# skip
allergies = Allergies.new(248)
expected = %w(strawberries tomatoes chocolate pollen cats)
assert_equal expected, allergies.list
end

def test_allergic_to_everything
# skip
allergies = Allergies.new(255)
expected = %w(eggs peanuts shellfish strawberries tomatoes chocolate pollen cats)
assert_equal expected, allergies.list
end

def test_ignore_non_allergen_score_parts
# skip
allergies = Allergies.new(509)
expected = %w(eggs shellfish strawberries tomatoes chocolate pollen cats)
assert_equal expected, allergies.list
end
end
65 changes: 65 additions & 0 deletions atbash-cipher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Atbash Cipher

Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.

The Atbash cipher is a simple substitution cipher that relies on
transposing all the letters in the alphabet such that the resulting
alphabet is backwards. The first letter is replaced with the last
letter, the second with the second-last, and so on.

An Atbash cipher for the Latin alphabet would be as follows:

```plain
Plain: abcdefghijklmnopqrstuvwxyz
Cipher: zyxwvutsrqponmlkjihgfedcba
```

It is a very weak cipher because it only has one possible key, and it is
a simple monoalphabetic substitution cipher. However, this may not have
been an issue in the cipher's time.

Ciphertext is written out in groups of fixed length, the traditional group size
being 5 letters, and punctuation is excluded. This is to make it harder to guess
things based on word boundaries.

## Examples
- Encoding `test` gives `gvhg`
- Decoding `gvhg` gives `test`
- Decoding `gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt` gives `The quick brown fox jumps over the lazy dog.`

* * * *

For installation and learning resources, refer to the
[exercism help page](http://exercism.io/languages/ruby).

For running the tests provided, you will need the Minitest gem. Open a
terminal window and run the following command to install minitest:

gem install minitest

If you would like color output, you can `require 'minitest/pride'` in
the test file, or note the alternative instruction, below, for running
the test file.

In order to run the test, you can run the test file from the exercise
directory. For example, if the test suite is called
`hello_world_test.rb`, you can run the following command:

ruby hello_world_test.rb

To include color from the command line:

ruby -r minitest/pride hello_world_test.rb

The test files may have the execution bit set so you may also be able to
run it like this:

./hello_world_test.rb

## Source

Wikipedia [http://en.wikipedia.org/wiki/Atbash](http://en.wikipedia.org/wiki/Atbash)

## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

31 changes: 31 additions & 0 deletions atbash-cipher/atbash_cipher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Atbash
def self.encode(plain_value)
plain_value.gsub!(/[ .,]/,'')
plain_value.downcase!
@array_char=('a'..'z').to_a
string_to_array=plain_value.split('')
n=0
cipher_text=''
while n != string_to_array.length
if string_to_array[n] =~ /[a-z]/
temp_index=@array_char.index(string_to_array[n]).to_i
cipher_text += @array_char[25 - temp_index]
else
cipher_text += string_to_array[n].to_s
end
n += 1
end
contain_string=''
temp_div=0
temp_array=cipher_text.split('')
(0...temp_array.length).each do |i|
if(temp_div % 5 == 0)
contain_string += ' '
end
contain_string += temp_array[i]
temp_div += 1
end
return contain_string.gsub!(/^[ ]+/,'')

end
end
48 changes: 48 additions & 0 deletions atbash-cipher/atbash_cipher_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env ruby
gem 'minitest', '>= 5.0.0'
require 'minitest/autorun'
require_relative 'atbash_cipher'

class AtbashTest < Minitest::Test
def test_encode_no
assert_equal 'ml', Atbash.encode('no')
end

def test_encode_yes
# skip
assert_equal 'bvh', Atbash.encode('yes')
end

def test_encode_OMG
# skip
assert_equal 'lnt', Atbash.encode('OMG')
end

def test_encode_O_M_G
# skip
assert_equal 'lnt', Atbash.encode('O M G')
end

def test_encode_long_word
# skip
assert_equal 'nrmwy oldrm tob', Atbash.encode('mindblowingly')
end

def test_encode_numbers
# skip
assert_equal('gvhgr mt123 gvhgr mt',
Atbash.encode('Testing, 1 2 3, testing.'))
end

def test_encode_sentence
# skip
assert_equal 'gifgs rhurx grlm', Atbash.encode('Truth is fiction.')
end

def test_encode_all_the_things
# skip
plaintext = 'The quick brown fox jumps over the lazy dog.'
cipher = 'gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt'
assert_equal cipher, Atbash.encode(plaintext)
end
end
66 changes: 66 additions & 0 deletions binary/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Binary

Write a program that will convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles

Implement binary to decimal conversion. Given a binary input
string, your program should produce a decimal output. The
program should handle invalid inputs.

## Note
- Implement the conversion yourself.
Do not use something else to perform the conversion for you.

## About Binary (Base-2)
Decimal is a base-10 system.

A number 23 in base 10 notation can be understood
as a linear combination of powers of 10:

- The rightmost digit gets multiplied by 10^0 = 1
- The next number gets multiplied by 10^1 = 10
- ...
- The *n*th number gets multiplied by 10^*(n-1)*.
- All these values are summed.

So: `23 => 2*10^1 + 3*10^0 => 2*10 + 3*1 = 23 base 10`

Binary is similar, but uses powers of 2 rather than powers of 10.

So: `101 => 1*2^2 + 0*2^1 + 1*2^0 => 1*4 + 0*2 + 1*1 => 4 + 1 => 5 base 10`.

* * * *

For installation and learning resources, refer to the
[exercism help page](http://exercism.io/languages/ruby).

For running the tests provided, you will need the Minitest gem. Open a
terminal window and run the following command to install minitest:

gem install minitest

If you would like color output, you can `require 'minitest/pride'` in
the test file, or note the alternative instruction, below, for running
the test file.

In order to run the test, you can run the test file from the exercise
directory. For example, if the test suite is called
`hello_world_test.rb`, you can run the following command:

ruby hello_world_test.rb

To include color from the command line:

ruby -r minitest/pride hello_world_test.rb

The test files may have the execution bit set so you may also be able to
run it like this:

./hello_world_test.rb

## Source

All of Computer Science [http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-](http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-)

## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

Loading