Python Labs
-
Write a countdown timer that counts for 120 seconds (ticks every second), printing the remaining seconds to wait in each tick
-
Change your countdown timer to show remaining time like a watch, i.e.: 2:00 1:59 1:58 ... 1:20
| defmodule Seat do | |
| defstruct min_row: 0, max_row: 127, min_col: 0, max_col: 7 | |
| def from_string(str) do | |
| str | |
| |> String.graphemes | |
| |> Enum.reduce(%Seat{}, &Day5.process_letter/2) | |
| end | |
| def from_tuple({row, col}) do |
| defmodule Day4 do | |
| def read_input do | |
| File.read!("input/day4.txt") | |
| |> String.split("\n\n", trim: true) | |
| |> Enum.map(&to_passport/1) | |
| end | |
| def to_passport(str) do | |
| str | |
| |> String.split(~r{\s+}, trim: true) |
| defmodule Day3 do | |
| def read_input do | |
| File.read!("input/day3.txt") | |
| |> String.split("\n", trim: true) | |
| |> Enum.map(&String.graphemes/1) | |
| |> Enum.map(&Enum.with_index/1) | |
| |> Enum.with_index | |
| |> Enum.flat_map(fn {line, row} -> Enum.map(line, fn {el, col} -> {{row, col}, (if el == "#", do: 1, else: 0) } end) end) | |
| |> Enum.into(%{}) | |
| end |
| defmodule Day2 do | |
| def read_input do | |
| File.read!("input/day2.txt") | |
| |> String.split("\n", trim: true) | |
| |> Enum.map(&(Regex.scan(~r/(\d+)-(\d+) (\w+): (.*)/, &1))) | |
| |> Enum.map(fn [[_, min, max, char, text]] -> { | |
| String.to_integer(min), | |
| String.to_integer(max), | |
| char, | |
| text |
| defmodule Day1 do | |
| def read_input do | |
| File.read!("input/day1.txt") | |
| |> String.split("\n", trim: true) | |
| |> Enum.map(&String.to_integer/1) | |
| end | |
| def part1 do | |
| values = read_input() | |
| for a <- values, b <- values, a + b == 2020, do: a * b |
| text = "some string (with parentheses (and also inner parentheses)) (yay) hi" | |
| stack = [] | |
| for i in range(len(text)): | |
| char = text[i] | |
| if char == "(": | |
| stack.append(char) | |
| elif char == ")": | |
| stack.pop() | |
| if len(stack) == 0: |
| #!/usr/bin/env ruby | |
| require 'csv' | |
| require 'json' | |
| def print_as_json(data) | |
| $/ = "\n" | |
| csv = CSV.new(data, :headers => true, liberal_parsing: true) | |
| puts csv.to_a.map {|row| row.to_hash }.to_json | |
| $/ = "---===---" |
| from PyQt5.QtCore import * | |
| from PyQt5.QtWidgets import * | |
| from ui_mainwindow import Ui_MainWindow | |
| from functools import partial | |
| import sys | |
| class MainWindow(QMainWindow): | |
| def __init__(self): | |
| super().__init__() |
Python Labs
Write a countdown timer that counts for 120 seconds (ticks every second), printing the remaining seconds to wait in each tick
Change your countdown timer to show remaining time like a watch, i.e.: 2:00 1:59 1:58 ... 1:20
| (defn power | |
| [serial x y] | |
| (let [ | |
| rack-id (+ x 10) | |
| ] | |
| (- | |
| (Math/floor |