Skip to content

Instantly share code, notes, and snippets.

View travisjungroth's full-sized avatar

Travis Jungroth travisjungroth

View GitHub Profile
127.0.0.1 reddit.com
127.0.0.1 news.ycombinator.com
127.0.0.1 imgur.com
Solve all problems in order. Do not copy and paste, but do refer to previously solved problems. Show me each problem as it's solved if I'm available.
The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined as follows: start with any positive integer n. Then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
Given positive integer n, return a list of the of the Collatz sequence from n to 1. Recursive and iterative.
3 -> [3, 10, 5, 16, 8, 4, 2, 1]
Given positive integer n, return the number of steps required to go from n to 1. Recursive and iterative.
3 -> 7
"""
There are two main keywords for making loops of code in Python: for and while.
There are other ways to make repeating code (comprehensions, generators, etc.) but these are the main
ones to used when you have a block of code you want to run over and over.
"""
# Use "for" when you have an iterable and you want to run some code on each item in it
for letter in 'abc':
print(letter)
@travisjungroth
travisjungroth / linked_lists.py
Last active May 8, 2019 01:33
Examples of three types of linked lists
"""
These are classes I coded up to understand how different linked lists worked.
They all accept and return the items held, not node instances.
"""
from abc import ABC, abstractmethod
from collections.abc import Iterable, Reversible
from typing import Optional
class AbstractLinkedNode(ABC):
all-[name] - channels everyone should be on
ask-[name] - channel to interact with a team
team-[name] - channel for a team
proj-[name] - channels about work with an end date (prolly cross functional)
talk-[name] RF specific endless discussions (hiring)
pings-[name] channels that go beep (intercom, code-reviews)
client-[name] channel shared with a client (not to talk about them!)
chat-[name] - general subject discussions not RF specific (design, travel, music, product)
from collections import deque
from typing import Dict, Hashable, MutableSet, MutableSequence, Set, TypeVar, Union, Generic, List, Generator
Node = Hashable
Adjacent = Union[MutableSequence[Hashable], MutableSet[Hashable]]
def depth_first_connected_nodes_iterative(graph: Dict[Node, Adjacent],
start: Node) -> Set[Node]:
to_visit = [start]
from graphs import depth_first_connected_nodes_iterative
graph = {
'A': {
'B',
},
'B': {
'C',
'D',
[
{
"date": "1/25/2020",
"title": "The business of SaaS",
"url": "https://stripe.com/atlas/guides/business-of-saas"
},
{
"date": "5/19/2021",
"title": "Do The Real Thing",
"url": "https://www.scotthyoung.com/blog/2020/05/04/do-the-real-thing/"
@travisjungroth
travisjungroth / clojure-syllabus.txt
Created August 31, 2020 14:30
Clojure Syllabus
PF: Introduction to Clojure V2
PF: 3 Functional Tools
PF: JVM Fundamentals for Clojure
PF: Repl-Driven Development in Clojure
PF: Clojure Collections
PF: Clojure Scope
PF: Recursion 101
PF: Namespaces
PF: Leiningen
PF: Web Development in Clojure
@travisjungroth
travisjungroth / recursion.py
Created January 19, 2021 02:20
A tiny introduction to recursion in Python
from typing import List, Optional, Sequence
# A recursive function is a function that calls itself. They're an alternative option to iteration, like using a while
# or for loop. Sometimes, they can make code easier to read and write. The examples below are overly simplified and
# have obviously better alternatives.
def multiply_string(s: str, n: int) -> str:
# There are 3 main parts to a recursive function.
# 1. A way to go to either the base case (no recursion) or recursive case (function calls itself).