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
| defmodule AlternatingArray do | |
| @moduledoc """ | |
| An alternating array is a list of any length in which two (not necessarily different) | |
| values are alternating (all even-indexed items are equal, and all odd-indexed items are equal). | |
| Given an array, return true if it is alternating. | |
| Examples | |
| -------- | |
| [] -> True | |
| [1] -> True |
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 latin_square(n): | |
| if n <= 0: | |
| return [] | |
| numbers = list(range(1, n + 1)) | |
| result = [] | |
| for i in range(n): | |
| result.append(numbers.copy()) | |
| # Rotate left: move first element to the end |
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
| """ | |
| Make a data structure for a deck of cards, | |
| and implement a `shuffle()` method, and a `draw(n)` method (where you draw `n` cards). | |
| Calling `draw()` when the deck is empty returns an empty array. | |
| URL: https://buttondown.com/cassidoo/archive/dont-watch-the-clock-do-what-it-does-keep-going | |
| """ | |
| VALID_SUITS = ['♠', '♥', '♣', '♦'] | |
| VALID_SYMBOLS = ['A', 'K', 'J', 'Q'] | |
| import random |
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
| import gleam/list | |
| import gleam/result | |
| pub fn oddsum(arr1, arr2) { | |
| list.map(arr1, fn(a) { | |
| list.map(arr2, fn(b) { [a, b]})}) |> list.flatten |> list.map(fn(x){ | |
| case {{result.unwrap(list.first(x), 0) + result.unwrap(list.last(x), 0)} % 2} { | |
| 1 -> x | |
| _ -> [] | |
| } |
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
| import gleam/int | |
| import gleam/io | |
| import gleam/list | |
| import gleam/string | |
| pub fn chars_at_position(pos: Int, as_char: List(List(String))) { | |
| // given a position, create a list of characters | |
| list.map(as_char, fn(x) { | |
| case { list.last(list.take(x, pos)) } { | |
| Ok(val) -> val |
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
| from itertools import groupby | |
| def compress(items): | |
| if not items: | |
| return [] | |
| result = [] | |
| for item, group in groupby(items): | |
| group_length = sum(1 for _ in group) | |
| result.append(item) |
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
| """ | |
| Given an array of objects representing ingredients (each with a name and amount per serving), and a target number of servings, write a function to calculate the required amount of each ingredient for the target servings. Return the results as an array of objects with name and amount. Can you do this in less than 5 lines? In one? | |
| Example: | |
| const ingredients = [ | |
| { name: "flour", amount: 200 }, // 200g per | |
| { name: "sugar", amount: 100 }, // 100g per | |
| { name: "eggs", amount: 2 } // 2 eggs per | |
| ]; | |
| const targetServings = 3; |
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
| NATO_DICTIONARY = { | |
| "A": "Alpha", | |
| "B": "Bravo", | |
| "C": "Charlie", | |
| "D": "Delta", | |
| "E": "Echo", | |
| "F": "Foxtrot", | |
| "G": "Golf", | |
| "H": "Hotel", | |
| "I": "India", |
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
| 1 | |
| 00:00:00,000 --> 00:00:24,000 | |
| It's a simple game. You have 15 players. Give one of them the ball. Get it into the net. | |
| 2 | |
| 00:00:24,000 --> 00:00:26,000 | |
| Very simple. Isn't it? | |
| 3 | |
| 00:00:26,000 --> 00:00:31,000 |
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
| """ | |
| Datastructures | |
| 1. Tuple | |
| 2. List | |
| 3. Set | |
| 4. Dictionary | |
| 5. Class | |
| """ | |
| import datetime |
NewerOlder