Given a string containing brackets []
, braces {}
, parentheses ()
,
or any combination thereof, verify that any and all pairs are matched and nested correctly.
sed -Enf parentheses.sed parentheses.txt
def word_key: ascii_downcase | explode | sort; | |
(.subject | length) as $size | | |
(.subject | ascii_downcase) as $subject | | |
(.subject | word_key) as $subject_key | | |
def is_candidate: length == $size and ascii_downcase != $subject; | |
def is_anagram: word_key == $subject_key; | |
[ |
#!/usr/bin/env bash | |
main () { | |
local -r phrase=${1@L} | |
local symbols=${phrase//[[:space:]-]/} | |
for letter in {a..z} | |
do | |
symbols="${symbols/$letter/}" | |
done |
#!/use/bin/env gawk --exec | |
# | |
# Copyright (c) 2023 Jegors Čemisovs | |
# License: Apache-2.0 license | |
# | |
# The script extracts if statements from Java code. | |
# | |
BEGIN { | |
RS = "[[:space:]]*[;{][[:space:]]*" | |
} |
#!/usr/bin/gawk --exec | |
# | |
# Copyright (c) 2023 Jegors Čemisovs | |
# License: Apache-2.0 license | |
# | |
# Correctly determine the fewest number of coins to be given to a customer | |
# such that the sum of the coins' value would equal the correct amount of change. | |
# | |
# The first line of the file is a list where the nominations | |
# and all subsequent lines are the amounts to provide change. |
export default function calculateBattle(defArmy, attArmy) { | |
const MAX_ATTACKER_ARMY = 8; | |
const MAX_DEFENDER_ARMY = MAX_ATTACKER_ARMY * 4; | |
const HITS = 2; | |
const ATTACKER_STATS = MAX_ATTACKER_ARMY * HITS + 1; | |
const DEFENDER_STATS = MAX_DEFENDER_ARMY * HITS + 1; | |
const STATS = ATTACKER_STATS + DEFENDER_STATS; | |
const cache = new Array(ATTACKER_STATS * DEFENDER_STATS); | |
return calculateStatistics(1, defArmy.length * HITS, attArmy.length * HITS); |
import java.util.Scanner; | |
import java.util.Objects; | |
public class Main | |
{ | |
public static void main(String[] args) { | |
Object obj = null; | |
if (obj == null) { |
import java.util.Scanner; | |
import static java.util.function.Predicate.not; | |
class Main { | |
public static void main(String[] args) { | |
System.out.println( | |
new Scanner(System.in) | |
.tokens() | |
.takeWhile(not("0"::equals)) | |
.count() |
import java.util.Arrays; | |
import java.util.Scanner; | |
public class Main { | |
public static int findSecondLargestNumber(int[] numbers) { | |
// write your code here | |
return Arrays.stream(numbers) | |
.distinct() | |
.map(i -> -i) |
// Bad Code Coding Challenge #51 - Dude, where's my turtle? | |
// https://www.reddit.com/r/badcode/comments/k8eh7a/bad_code_coding_challenge_51_dude_wheres_my_turtle/ | |
public class Turtle { | |
public static void main(String[] args) { | |
System.out.println(java.text.MessageFormat.format( | |
"x = {1}, y = {0}, direction = {2, choice, 0#north|1#east|2#south|3#west}", | |
new java.util.Scanner(System.in).useDelimiter("\\R").tokens() | |
.mapToInt(s -> Integer.parseInt(s.substring(7).trim()) << s.charAt(0) / 'r' * ' ' / 2) | |
.mapToObj(data -> new Integer[] {(int)(short) data, (data >> 16) / 90}) |