Skip to content

Instantly share code, notes, and snippets.

View onacit's full-sized avatar

Jin Kwon onacit

  • WeMakePrice
  • Seoul, Korea
View GitHub Profile
class NumberCodec {
}
@onacit
onacit / Ieee754Binary16.java
Last active February 24, 2020 12:44
Half-precision floating-point in Java
package p_459caefadb7cee1b2aaa275bcb3013fc;
import static java.lang.Float.floatToIntBits;
import static java.lang.Float.intBitsToFloat;
import static java.lang.Math.pow;
import static java.lang.Math.scalb;
public class Ieee754Binary16 {//implements Comparable<Half> {
// -----------------------------------------------------------------------------------------------------------------
@onacit
onacit / Half.java
Created February 8, 2020 12:45
Half-precision floating-point in Java
public class Half {
}
@onacit
onacit / MontyHallProblem.java
Last active November 9, 2019 14:21
Run Monty Hall Problem with Random
import java.security.*;
import java.util.*;
import java.util.concurrent.atomic.*;
public class MontyHallProblem {
//private static final long COUNT = 1048576L;
private static final long COUNT = 30000L;
static { assert COUNT > 0L; }
private static final int DOORS = 3;
static { assert DOORS > 0; }
public static void main(final String... args) throws Exception {
@onacit
onacit / ChronoUnitMatrix.java
Last active December 2, 2018 08:51
Prints information from java.time.temporal.ChronoUnit.
import java.time.temporal.*;
public class ChronoUnitMatrix {
public static void main(final String... args) {
System.out.printf("%-10s%-6s%-6s%s\n", "name", "time", "date",
"duration (estimated) (seconds)");
System.out.printf("%-10s%-6s%-6s%s\n", "---------", "-----", "-----",
"---------------------------------------------------------------");
for (final ChronoUnit value : ChronoUnit.values()) {
@onacit
onacit / Fibonacci.java
Last active November 30, 2018 09:18
Get fibonacci number of given nth term.
import java.math.BigInteger;
public class Fibonacci {
public static void main(final String... args) {
final int n = Integer.parseInt(args[0]);
if (n < 0) {
throw new IllegalArgumentException("n(" + n + ") is negative");
}
if (n == 0) {
@onacit
onacit / main.c
Last active June 18, 2018 06:58
Main function of C
#include <assert.h>
#include <stdio.h>
/*
* 5.1.2.2.1 Program startup
* N1548
*/
int main(int argc, char *argv[]) {
// The value of argc shall be nonnegative.
assert(argc >= 0);