Skip to content

Instantly share code, notes, and snippets.

Designing an append() method that would concatenate a second queue onto the calling queue in Java. The method needed to traverse the appended queue’s nodes instead of dequeueing its items.

My solution at the time involved iterating until the node that was currently being checked had a null pointer and then transferring the node contents one more time after my while loop condition was met (since the node with the null pointer never got read/appended), but I could’ve iterated through by using the size() method at the start and iterating while i < [variable storing size()]

package jv.test;

import static java.lang.System.out;
import java.util.*;
import java.util.stream.*;
@Transfusion
Transfusion / lego_blocks.py
Created December 23, 2021 03:18
HackerRank "Lego Blocks" problem, naive Python solution
#!/bin/python3
import math
import os
import random
import re
import sys
import functools
#
@Transfusion
Transfusion / gist:852fbebb67a4547d5581b73d99c71317
Created September 11, 2021 18:36
mediapipe face mesh baka mitai profile
$ LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH python bakamitai.py
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
^C 212361 function calls in 19.485 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
4461 0.032 0.000 19.486 0.004 /home/transfusion/mp_env/lib64/python3.9/site-packages/mediapipe/python/solutions/face_mesh.py:102(process)
4461 17.678 0.004 19.454 0.004 /home/transfusion/mp_env/lib64/python3.9/site-packages/mediapipe/python/solution_base.py:267(process)
4461 0.043 0.000 0.844 0.000 /home/transfusion/mp_env/lib64/python3.9/site-packages/mediapipe/python/solution_base.py:515(_get_packet_content)
{
"field":"e2571d6a-5e22-4efe-afc6-4bd1964376ee",
"field2":"something else",
"field3":123490,
"field4":[
"e2571d6a-5e22-4efe-afc6-4bd1964376ee",
"list",
"of",
"things"
]
from collections import deque
class Solution:
def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int:
wordLength = len(beginWord)
wordDict = {}
for i in range(len(wordList)):
wordDict[wordList[i]] = i
@Transfusion
Transfusion / interpreter_transfusion_fixed.py
Created November 14, 2020 08:17
obama's interpreter
# Dependencies
import os
import sys, traceback
import readline
from platform import python_version
version = "1.0-stable"
# Inbuilt commands
@Transfusion
Transfusion / topo.py
Created September 15, 2020 11:02
edgelord N tasks topological sorting
# "There's a set of N tasks, from which some have to be done before the other. The order is described by a 2D array T[N][N]. If T[a][b] = 1, then the task 'a' has to be done before the task 'b'. In the case of T[a][b] = 2, the task b has to be done earlier, and when T[a][b] = 0 the order doesn't matter. Implement a function tasks(T), which for the given array T returns an array with the tasks in the order of execution."
# Example: For the array T = [ [0,2,1,1], [1,0,1,1], [2,2,0,1], [2,2,2,0] ] the result is [1,0,2,3]
# an arbitrary array (because there can be more than one solution to a particular graph)
T = [ [0,2,1,1], [1,0,1,1], [2,2,0,1], [2,2,2,0] ]
import sys
@Transfusion
Transfusion / zbig.py
Last active September 15, 2020 10:06
edgelord dp frog problem
# your code goes here
# "The frog Zbigniew jumps on a number axis.
# It has to get from 0 to n - 1, jumping only in the positive direction.
# The jump from the number 'i' to number 'j' ( j > i ) costs Zbigniew ( j - i ) units of energy,
# but lucky him, on certain slots - even on the zeroth - exist snacks with a certain energy value (the energy value of a snack is added to the current energy of Zbigniew).
# Implement a function zbigniew(A), which gets on input an array A, with the lenght len(A) = n,
# in which each slot contains the energy value of the laying snack.
# The function should output the minimal amount of jumps needed to get from 0 to n-1 or -1 if it isn't possible.
# Tip: You should consider the function f(i, y) returning the minimal amount of jumps to get to a slot having exactly y energy left.
@Transfusion
Transfusion / purple_ripcord_theme.json
Created August 5, 2020 07:05
Purple Ripcord Theme
{
"alternate_base": "#4b0064",
"base": "#3b0259",
"button": "#4e3551",
"chat_timestamp": "#ffc6ff",
"disabled_button": "#451f48",
"disabled_icon": "#8d8b8b",
"disabled_text": "#8d8b8b",
"highlight": "#d3d2d0",
"highlighted_text": "#2d2c27",
@Transfusion
Transfusion / candies.py
Created June 21, 2020 06:29
TLE DP Round C 2020 Candies
T = int(input())
# update function
def build_dp(N, A, dp1, dp2, start):
# dp2 is the regular prefix sum
if start == 0:
dp1[0] = A[0]
dp2[0] = A[0]