GithubHelp home page GithubHelp logo

the-vampiire / hacktoberithms Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 70.0 181 KB

Python & JavaScript solutions only! algorithms to practice javascript, python, git and contribute to an open source repo for hacktoberfest!

License: MIT License

Python 97.01% JavaScript 2.99%
hacktoberfest algorithms practice-python practice-git practice-javascript

hacktoberithms's People

Stargazers

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

Watchers

 avatar

hacktoberithms's Issues

Lovely Lucky Lambs

from Google Foobar

Challenge

  • Write a function called answer(total_lambs), where total_lambs is the integer number of LAMBs in the handout you are trying to divide.
  • It should return an integer which represents the difference between the minimum and maximum number of henchmen who can share the LAMBs (that is, being as generous as possible to those you pay and as stingy as possible, respectively) while still obeying all of the above rules to avoid a revolt.

Problem Statement:
Lovely Lucky LAMBs

Being a henchman isn't all drudgery. Occasionally, when Commander Lambda is feeling generous, she'll hand out Lucky LAMBs (Lambda's All-purpose Money Bucks). Henchmen can use Lucky LAMBs to buy things like a second pair of socks, a pillow for their bunks, or even a third daily meal!
However, actually passing out LAMBs isn't easy. Each henchman squad has a strict seniority ranking which must be respected - or else the henchmen will revolt and you'll all get demoted back to minions again!
There are 4 key rules which you must follow in order to avoid a revolt:
1. The most junior henchman (with the least seniority) gets exactly 1 LAMB. (There will always be at least 1 henchman on a team.)
2. A henchman will revolt if the person who ranks immediately above them gets more than double the number of LAMBs they do.
3. A henchman will revolt if the amount of LAMBs given to their next two subordinates combined is more than the number of LAMBs they get. (Note that the two most junior henchmen won't have two subordinates, so this rule doesn't apply to them. The 2nd most junior henchman would require at least as many LAMBs as the most junior henchman.)
4. You can always find more henchmen to pay - the Commander has plenty of employees. If there are enough LAMBs left over such that another henchman could be added as the most senior while obeying the other rules, you must always add and pay that henchman.

notes

Note that you may not be able to hand out all the LAMBs. A single LAMB cannot be subdivided. That is, all henchmen must get a positive integer number of LAMBs.
For instance, if you had 10 LAMBs and were as generous as possible, you could only pay 3 henchmen (1, 2, and 4 LAMBs, in order of ascending seniority), whereas if you were as stingy as possible, you could pay 4 henchmen (1, 1, 2, and 3 LAMBs). Therefore, answer(10) should return 4-3 = 1.

sample inputs / outputs

Inputs:
(int) total_lambs = 10
Output:
(int) 1
Inputs:
(int) total_lambs = 143
Output:
(int) 3

Mutations

Credit: adapted from Free Code Camp

Challenge

Write a function that satisfies the following rules:

  • Return true if the string in the first element of the list contains all of the letters of the string in the second element of the list.

examples

["hello", "Hello"]

  • should return true because all of the letters in the second string are present in the first, ignoring case.

["hello", "hey"]

  • should return false because the string "hello" does not contain a "y".

["Alien", "line"]

  • should return true because all of the letters in "line" are present in "Alien".

Coin Gift

Intro
It's Maria's birthday today and Alfonso has brought a string as a gift. Maria isn't happy with the gift and comes up with a plan to exchage it. First, generate one string of size 3, and ask Alfonso to give as many coins as the number of times the string occurs as sub-sequence in Alfonso's string. Determine the number of coins Maria will get, i.e given two strings mariaString and alfonsoString, the goal is to find the count of the number of times mariaString appears as a sub-sequence in the alfonsoString. A sub-sequence is created by eliminating an number of characters from a string, from 0 to the length of the string, without changing the order of the characters retained.

for example:
mariaString = ABC
alfonsoString = ABCBABC
mariaString appears 5 times as subsqeuence in alfonsoString at 1-indexed positions (1,2,3), (1,2,7), (1,4,7), (1,6,7), and (5,6,7)

another example:
mariaString = ELO
alfonsoString = HELLOWORLD
output = 4
ELO appears as sub-sequence of HELLOWORLD at positions (2,3,5), (2,3,7), (2,4,5) and (2,4,7)

Function Description
The function should return the number of times Maria's string appears as the sub-sequence in Alfonso's string.

Multiple Cash Registers

Write a function which takes two arguments: a list of customers and the number of open cash registers. Each customer is represented by an integer which indicates the amount of time needed to checkout. Assuming that customers are served in their original order, your function should output the minimum time required to serve all customers.

checkout_time([5, 1, 3], 1) should return 9
checkout_time([10, 3, 4, 2], 2) should return 10 because while the first register is busy serving customer[0] the second register can serve all remaining customers

Sum of All Numbers

Credit: Free Code Camp

Challenge

  • Write a function called sum_all() that takes a list of two numbers.
  • Return the sum of those two numbers plus the sum of all the numbers between them.

notes

The lowest number will not always come first.

sample outputs

  • sum_all([1, 4]) should return 10.
  • sum_all([4, 1]) should return 10.

Sum Earnings

Challenge

  • write a function that accepts a comma-separated string input of earning/spending activity and returns the sum of earnings as a single int value
  • if at any point the spending (negative) value is greater than the sum of earned (positive) values before it then the streak ends and the count should start over

We have a list in string type separated by commas that represented buy or sell activity. Positive value for selling and negative value for buying activity.
For example, in the following string, this user sold something for $7 on the 2nd day, and something for $2 on the 4th day, and then bought something for $12 on the 5th day, and so on.

0,7,0,2,-12,3,0,2

This user's highest earnings streak is $5, which started on the 6th day and ended on the 8th day. The streak does not start before the 6th day because the user spent $12 on the 5th and broke earlier streak on $9.

test data

input:
1,3,-2,1,2
output:
5

input:
0,7,0,2,-12,3,0,2
output:
5

starter code

def sum_earnings(input):

notes

  • If the user did not do anything (i.e. 0,0,0,0,0) or only bought things without selling anything (i.e. -4,-3,-7,-1), then it should output with 0.
  • Your program should be able to handle a comma-separated string consisting of any number of values.
  • Your program should also be able to handle invalid input. If an invalid input is given, it should output 0. some examples of invalid input:
    qwerty
    ,,3,,4
    1,2,v,b,3

Power Hungry

Challenge

Problem Statement:
Power Hungry

Commander Lambda's space station is HUGE. And huge space stations take a LOT of power. Huge space stations with doomsday devices take even more power. To help meet the station's power needs, Commander Lambda has installed solar panels on the station's outer surface.
But the station sits in the middle of a quasar quantum flux field, which wreaks havoc on the solar panels. You and your team of henchmen has been assigned to repair the solar panels, but you can't take them all down at once without shutting down the space station (and all those pesky life support systems!).
You need to figure out which sets of panels in any given array you can take offline to repair while still maintaining the maximum amount of power output per array, and to do THAT, you'll first need to figure out what the maximum output of each array actually is.

Write a function answer(xs) that takes a list of integers representing the power output levels of each panel in an array, and returns the maximum product of some non-empty subset of those numbers.

So for example, if an array contained panels with power output levels of [2, -3, 1, 0, -5], then the maximum product would be found by taking the subset: xs[0] = 2, xs[1] = -3, xs[4] = -5, giving the product 2*(-3)*(-5) = 30. So answer([2,-3,1,0,-5]) will be "30".

Each array of solar panels contains at least 1 and no more than 50 panels, and each panel will have a power output level whose absolute value is no greater than 1000 (some panels are malfunctioning so badly that they're draining energy, but you know a trick with the panels' wave stabilizer that lets you combine two negative-output panels to produce the positive output of the multiple of their power values).

The final products may be very large, so give the answer as a string representation of the number.

sample inputs / outputs

Inputs:
(int list) xs = [2, 0, 2, 2, 0]
Output:
(string) "8"
Inputs:
(int list) xs = [-2, -3, 4, -5]
Output:
(string) "60"

Profile Lookup

Credit: Adapted from Free Code Camp

Challenge

We have a list of dictionaries representing different people in our contacts list.

Complete the look_up_profile() function that takes name and a field as arguments included below

The function should check if name is an actual contact's firstName and the given field exists in that contact dictionary.

If both are true, then return the "value" of that field.

If name does not correspond to any contacts then return "No such contact"

If the field does not correspond to any valid properties of a contact found to match name then return "No such property"

starter code

contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["JavaScript", "Gaming", "Foxes"]
    }
];


def look_up_profile(name, field):
  pass # fill in your solution here


// Change these values to test your function
look_up_profile("Akira", "likes")

Valid Parenthesis

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

  • Open brackets must be closed by the same type of brackets.
  • Open brackets must be closed in the correct order.
  • Note that an empty string is also considered valid.

Examples:

has_valid_parens("()")
True
has_valid_parens("()[]{}")
True
has_valid_parens("(]")
False
has_valid_parens("([)]")
False
has_valid_parens("{[]}")
True

Braille Translation

from Google Foobar

Challenge

Problem Statement:
Braille Translation

Because Commander Lambda is an equal-opportunity despot, she has several visually-impaired minions.
But she never bothered to follow intergalactic standards for workplace accommodations, so those minions have a hard time navigating her space station.
You figure printing out Braille signs will help them, and - since you'll be promoting efficiency
at the same time - increase your chances of a promotion.

Braille is a writing system used to read by touch instead of by sight. Each character is composed of 6 dots in a 2x3 grid, where each dot can either be a bump or be flat (no bump).
You plan to translate the signs around the space station to Braille so that the minions under Commander Lambda's command can feel the bumps on the signs and "read" the text with their touch.

The special printer which can print the bumps onto the signs expects the dots in the
following order:
1 4
2 5
3 6

So given the plain text word "code", you get the Braille dots:
11 10 11 10
00 01 01 01
00 10 00 00
where 1 represents a bump and 0 represents no bump.
Put together, "code" becomes the output string "100100101010100110100010".

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.