-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add picture story and assessment rule
- Loading branch information
Showing
14 changed files
with
41 additions
and
48 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,7 @@ | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
public class Challenge { | ||
|
||
// TODO: Make empty before publish | ||
String weightedSort(String text) { | ||
var cleanedText = text | ||
.replaceAll("[-']", "") | ||
.replaceAll("[.,!?]", " "); | ||
|
||
var lines = cleanedText.split("\s+"); | ||
var result = Arrays.stream(lines) | ||
.distinct() | ||
.map(l -> new Weighted(l)) | ||
.sorted() | ||
.map(Weighted::toString) | ||
.peek(l -> System.out.println(" " + l + " \\")) | ||
.collect(Collectors.joining(System.lineSeparator())); | ||
|
||
return result; | ||
} | ||
|
||
record Weighted(String word) implements Comparable<Weighted> { | ||
@Override | ||
public int compareTo(Weighted o) { | ||
var weightDelta = o.weight() - weight(); | ||
if (weightDelta != 0) { | ||
return weightDelta; | ||
} | ||
var length = Integer.min(o.word().length(), word.length()); | ||
for (int i = 0; i < length; i++) { | ||
var charDelta = o.word().charAt(i) - word.charAt(i); | ||
if (charDelta != 0) { | ||
return charDelta; | ||
} | ||
} | ||
return 0; | ||
} | ||
private int weight() { | ||
return word.chars().sum(); | ||
} | ||
@Override | ||
public String toString() { | ||
return "%s|%s".formatted(word, weight()); | ||
} | ||
return ""; | ||
} | ||
|
||
} |
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
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
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