reorder an int as big as possible

 I found https://www.codewars.com/ and solving a algorithm question, reorder given number as big as possible, example given 123, ordered biggest version is 321, so we just need to order digits separately and concatenate them, I wrote 2 approaches

public void testStreamCode() {
int num = 123;
AtomicReference<String> str = new AtomicReference<>();
String.valueOf(num).chars().boxed().sorted(Collections.reverseOrder()).forEach(c -> str.updateAndGet(v -> v + (c - 48)));
int parseInt = Integer.parseInt(str.get().replaceAll("null", ""));
assert parseInt == 321;
}

public void testArraysSortCode() {
int num = 7657585;
char[] c = String.valueOf(num).toCharArray();
Arrays.sort(c);
String s = "";
for (int i = c.length - 1; i >= 0; i--)
s += c[i];
Integer integer = Integer.valueOf(s);
assert integer == 8776555;
}
then CW gave another solution
public void cw() {
int num = 7657585;
int i1 = Integer.parseInt(String.valueOf(num)
.chars()
.mapToObj(i -> String.valueOf(Character.getNumericValue(i)))
.sorted(Comparator.reverseOrder())
.collect(Collectors.joining()));
assert i1 == 8776555;
}

I know java stream api looks cool and I decided to benchmark this. here is the result
Benchmark                                Mode  Cnt  Score   Error  Units
DemoApplicationTests.cw avgt 2 0.808 us/op
DemoApplicationTests.testArraysSortCode avgt 2 0.194 us/op
DemoApplicationTests.testStreamCode avgt 2 0.884 us/op
 
fastest is using arrays.sort(0.194) second is CW and last one is "testStreamCode". 

always free cloudresources

 https://www.learncloudnative.com/blog/2022-01-30-blog-on-oci

Here’s a quick comparison of always-free resources that each cloud vendor offers. It should be obvious this is not a detailed nor an apple-to-apple comparison. The offerings and service names differ between vendors, and so do terms provided by different providers. I only picked the compute, database, and storage options for a quick comparison.

Vendor Compute Databases Storage
AWS 750 hours (1yr only) 25 GB DynamoDB 100 GB storage gateway
Azure 750 hours (1yr only) Azure Cosmos DB (25 GB) 5 GB blob storage (1yr only)
Google 1 e2-micro instance per month Firestore (1 GB per project) 5 GB-months of regional storage
Oracle 4 ARM-based A1 cores and 24 GB memory NoSQL DB (3 tables with 25 GB per table) 10 GB object storage

solution:evenlySpaced

 Given three ints, a b c, one of them is small, one is medium and one is large. Return true if the three values are evenly spaced, so the difference between small and medium is the same as the difference between medium and large.

 

 

public boolean evenlySpaced(int a, int b, int c) {
  return (a – b == b – c) || (a – c == c – b) || (a – b == c – a);
}
 

tmux is allowed in CKAD

 Therefore I needed to learn tmux. main commands below

  • Ctrl+b " — split pane horizontally.
  • Ctrl+b % — split pane vertically.
  • Ctrl+b arrow key — switch pane.
  • Ctrl+b : - enter command mode, "setw -g mouse" <-to enable mouse scroll in tab 

looks nice

 

check https://cloudacademy.com/blog/micro-blog-1-of-3-what-i-wish-i-knew-before-i-took-the-ckad-multi-what/