• May 15, 2025 •AustinLeath
0 likes • 2 views
import java.util.Arrays; public class Main { public static int findMinNonCreatableSum(int[] coins) { // Sort the array Arrays.sort(coins); // Initialize max creatable sum int maxCreatable = 0; // Iterate through coins for (int coin : coins) { // If current coin is greater than maxCreatable + 1, // we found our answer if (coin > maxCreatable + 1) { return maxCreatable + 1; } // Add current coin to maxCreatable maxCreatable += coin; } // If we can create all sums up to maxCreatable, // the answer is maxCreatable + 1 return maxCreatable + 1; } public static void main(String[] args) { int[] coins = {2, 9, 1, 2, 7}; int result = findMinNonCreatableSum(coins); System.out.println("Smallest sum that cannot be created: " + result); } }
• Oct 7, 2023 •AustinLeath
0 likes • 5 views
import java.util.Arrays; public class LongestIncreasingSubsequence { public int lengthOfLIS(int[] nums) { if (nums.length == 0) { return 0; } int[] dp = new int[nums.length]; Arrays.fill(dp, 1); // Initialize all elements in dp array to 1, as each element itself is a valid subsequence of length 1. int maxLength = 1; // Initialize the maximum length to 1, considering a single element as the sequence. for (int i = 1; i < nums.length; i++) { for (int j = 0; j < i; j++) { if (nums[i] > nums[j]) { dp[i] = Math.max(dp[i], dp[j] + 1); // If nums[i] is greater than nums[j], update the longest subsequence length ending at i. } } maxLength = Math.max(maxLength, dp[i]); // Update the maximum length if needed. } return maxLength; } public static void main(String[] args) { LongestIncreasingSubsequence lis = new LongestIncreasingSubsequence(); int[] nums = {10, 9, 2, 5, 3, 7, 101, 18}; int result = lis.lengthOfLIS(nums); System.out.println("Length of the Longest Increasing Subsequence: " + result); // Output: 4 } }
• Feb 6, 2021 •Daedalus
0 likes • 0 views
public class Daedalus extends Athenian { private Story story; public ArrayList<Skill> skills = new ArrayList<Skill>(); public ArrayList<Athenian> children = new ArrayList<Athenian>(); public Daedalus(Story story, ArrayList<Skill> inherentSkills) { if(story != null) System.out.println("ERROR No one is created with a story."); skills.add(inherentSkills); } public Momento advanceStory(Scene s) { System.err.println("ERROR Don't know how to proceed..."); } } //██╗ ░█████╗░███╗░░░███╗ ██████╗░░█████╗░███████╗██████╗░░█████╗░██╗░░░░░██╗░░░██╗░██████╗ //██║ ██╔══██╗████╗░████║ ██╔══██╗██╔══██╗██╔════╝██╔══██╗██╔══██╗██║░░░░░██║░░░██║██╔════╝ //██║ ███████║██╔████╔██║ ██║░░██║███████║█████╗░░██║░░██║███████║██║░░░░░██║░░░██║╚█████╗░ //██║ ██╔══██║██║╚██╔╝██║ ██║░░██║██╔══██║██╔══╝░░██║░░██║██╔══██║██║░░░░░██║░░░██║░╚═══██╗ //██║ ██║░░██║██║░╚═╝░██║ ██████╔╝██║░░██║███████╗██████╔╝██║░░██║███████╗╚██████╔╝██████╔╝ //╚═╝ ╚═╝░░╚═╝╚═╝░░░░░╚═╝ ╚═════╝░╚═╝░░╚═╝╚══════╝╚═════╝░╚═╝░░╚═╝╚══════╝░╚═════╝░╚═════╝░
• Oct 15, 2022 •CodeCatch
public class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { ListNode head = new ListNode(0); ListNode handler = head; while(l1 != null && l2 != null) { if (l1.val <= l2.val) { handler.next = l1; l1 = l1.next; } else { handler.next = l2; l2 = l2.next; } handler = handler.next; } if (l1 != null) { handler.next = l1; } else if (l2 != null) { handler.next = l2; } return head.next; } }
0 likes • 6 views
public static String addBinary(){ // The two input Strings, containing the binary representation of the two values: String input0 = "1010"; String input1 = "10"; // Use as radix 2 because it's binary int number0 = Integer.parseInt(input0, 2); int number1 = Integer.parseInt(input1, 2); int sum = number0 + number1; return Integer.toBinaryString(sum); //returns the answer as a binary value; }
• Feb 1, 2022 •LeifMessinger
0 likes • 1 view
//Leif Messinger //Solves wordle //Needs a list of wordle words, newline separated and 5 characters each import java.util.*; import java.io.File; import java.io.FileNotFoundException; class WordleSolver { public static void printPointer(int position){ for(int i = 0; i < position; ++i){ System.out.print(" "); } System.out.print("^"); } public static void main(String[] args) throws FileNotFoundException{ if(args.length < 1) return; File dictionary = new File(args[0]); Scanner sc = new Scanner(dictionary); ArrayList<String> possibleWords = new ArrayList<String>(); while(sc.hasNextLine()){ possibleWords.add(sc.nextLine()); } Scanner input = new Scanner(System.in); while(possibleWords.size() > 0){ //Choose a word out of the possible words final int randomIndex = (int)(Math.random() * possibleWords.size()); String chosenWord = possibleWords.get(randomIndex); possibleWords.remove(randomIndex); System.out.println("Is it correct?"); for(int i = 0; i < chosenWord.length(); ++i){ System.out.println(chosenWord); printPointer(i); System.out.println(" y/n?"); if(input.nextLine().toLowerCase().contains("y")){ //Filter by correct character for(int possibleWord = possibleWords.size() - 1; possibleWord >= 0; --possibleWord){ //Has to be backwards for removing entries, also has to be int not unsigned if(possibleWords.get(possibleWord).charAt(i) != chosenWord.charAt(i)){ possibleWords.remove(possibleWord); } } } } System.out.println("Is it misplaced?"); //Stores a count of every letter misplaced short[] misplacedCounts = new short[('z'-'a')+1]; //Praise be the garbage collector for(int i = 0; i < chosenWord.length(); ++i){ System.out.println(chosenWord); printPointer(i); System.out.println(" y/n?"); if(input.nextLine().toLowerCase().contains("y")){ //Filter to make sure there's at least as many letters as needed ++misplacedCounts[(chosenWord.charAt(i) - 'a') - 1]; for(int possibleWord = possibleWords.size() - 1; possibleWord >= 0; --possibleWord){ //Has to be backwards for removing entries, also has to be int not unsigned int count = 0; for(int j = 0; j < possibleWords.get(possibleWord).length(); ++j){ if(possibleWords.get(possibleWord).charAt(j) == chosenWord.charAt(i)) ++count; } //If there's not enough of the character that we need, then we remove that from the list of possible characters if(count < misplacedCounts[(chosenWord.charAt(i) - 'a') - 1]){ possibleWords.remove(possibleWord); } } //Also filter out words where that letter doesn't belong there for(int possibleWord = possibleWords.size() - 1; possibleWord >= 0; --possibleWord){ //Has to be backwards for removing entries, also has to be int not unsigned if(possibleWords.get(possibleWord).charAt(i) == chosenWord.charAt(i)){ possibleWords.remove(possibleWord); continue; //Breaks the current word and moves on in the loop } } } } } } }