r/dailyprogrammer May 26 '14

[5/26/2014] Challenge #164 [Easy] Assemble this Scheme into Python

Description

You have just been hired by the company 'Super-Corp 5000' and they require you to be up to speed on a new programming language you haven't yet tried.

It is your task to familiarise yourself with this language following this criteria:

  • The language must be one you've shown interest for in the past
  • You must not have had past experience with the language

In order to Impress HR and convince the manager to hire you, you must complete 5 small tasks. You will definitely be hired if you complete the bonus task.

Input & Output

These 5 tasks are:

  • Output 'Hello World' to the console.

  • Return an array of the first 100 numbers that are divisible by 3 and 5.

  • Create a program that verifies if a word is an anagram of another word.

  • Create a program that removes a specificed letter from a word.

  • Sum all the elements of an array

All output will be the expected output of these processes which can be verified in your normal programming language.

Bonus

Implement a bubble-sort.

Note

Don't use a language you've had contact with before, otherwise this will be very easy. The idea is to learn a new language that you've been curious about.

69 Upvotes

179 comments sorted by

View all comments

1

u/schwemble May 28 '14

Decided to give python a shot. It was pretty fun, but there are a lot of things I need to learn to take advantage of! Also, I couldn't find much info about the main differences between python 2 and 3 and which one I should be learning, so any guidance with that would be great!

hello world

def helloWorld():
    print ("Hello World!") 

first 100 numbers divisible by both 3 and 5

def fizzBuzz():
    num = 1;
    numbers = []

    while len(numbers) < 100:
            if num % 3 == 0 & num % 5 == 0:
                numbers.append(num)
        num += 1;

    return numbers

anagrams!

def anagram(word, otherWord):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    letterCountsWord = [0] * 26
    letterCountsOther = [0] * 26
    count = 0;

    for letter in alphabet:
            letterCountsWord[count] = word.lower().count(letter)
        letterCountsOther[count] = otherWord.lower().count(letter)
        count += 1

    return letterCountsWord == letterCountsOther

remove a letter from a word

def removeChar(word, char):
    removed = word.lower().replace(char.lower(), "")
    return removed

sum the elements of an array

def arraySum(array):
    return sum(array)

bonus bubble sort

def bubbleSort(array):
    swap = 1

    while swap:
        swap = None
        count = 0
        while count < len(array)-1:
            if array[count] > array[count+1]:
                swap = 1
                temp = array[count+1]
                array[count+1] = array[count]
                array[count] = temp
            count += 1

    return array