This file contains 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
#!/usr/bin/env bash | |
main () { | |
local -r phrase=${1@L} | |
local symbols=${phrase//[[:space:]-]/} | |
for letter in {a..z} | |
do | |
symbols="${symbols/$letter/}" | |
done |
This file contains 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
#!/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:]]*" | |
} |
This file contains 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
#!/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. |
This file contains 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
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); |
This file contains 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 java.util.Scanner; | |
import java.util.Objects; | |
public class Main | |
{ | |
public static void main(String[] args) { | |
Object obj = null; | |
if (obj == null) { |
This file contains 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 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() |
This file contains 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 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) |
This file contains 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
// 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}) |
This file contains 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
public class WTF { | |
public static void main(String[] args) { | |
Integer W, F=0x2F; | |
for (int T; (W=T=F)>0 & W==F; ++F) | |
System.out.printf((W=T-=057)!=0 && 0!=(T%=011) ? "%5d":"%n%5d",(1+W/9)*++T); | |
} | |
} |
This file contains 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 java.util.Scanner; | |
import java.util.stream.IntStream; | |
import static java.util.stream.IntStream.range; | |
public class Main { | |
public static void main(String[] args) { | |
final var scanner = new Scanner(System.in); | |
final var n = scanner.nextInt(); |