Skip to content

Instantly share code, notes, and snippets.

@neojou
neojou / BigDecimalTest.java
Created January 22, 2015 13:48
BigDecimal : test example, show there is error when using double, and we can avoid it if use BigDecimal
package decimaltest;
import java.math.BigDecimal;
/**
*
* @author neojou
*/
public class BigDecimalTest {
@neojou
neojou / Guess.java
Created January 21, 2015 18:00
Guess number : example to use Scanner
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package neo.example;
import java.util.Scanner;
/**
@neojou
neojou / quadratic.py
Last active August 29, 2015 14:13
Python : example : quadratic : 二元一次方程式 - 平方根
import cmath
import math
import sys
def get_float(msg, allow_zero):
x = None
while x is None:
try:
x = float(input(msg))
@neojou
neojou / bigdigits.py
Last active December 31, 2020 17:24
Python : example : bigdigits.py : show numbers in big ASCII
import sys
Zero = [" *** ",
"* *",
"* *",
"* *",
"* *",
"* *",
" *** "]
One = [" * ",
@neojou
neojou / sum.py
Created January 18, 2015 14:32
Python : sum integers ; try except example ;
print("Type integers, each followed by Enter \n")
print(" ^D or ^E to finished \n")
total = 0
count = 0
while True:
try:
@neojou
neojou / GetLocation
Last active July 5, 2018 07:01
iOS : Swift : to get current location from iphone
//
// ViewController.swift
// GetLocation
//
// Created by neojou on 2014/11/23.
// Copyright (c) 2014年 neojou. All rights reserved.
//
import UIKit
import CoreLocation
@neojou
neojou / input
Created August 31, 2014 20:02
swift input : like scanf
import Foundation
func input() -> String {
var keyboard = NSFileHandle.fileHandleWithStandardInput()
var inputData = keyboard.availableData
return NSString(data: inputData, encoding:NSUTF8StringEncoding)
}
import CoreFoundation
func find_armstrong() -> Int[]
{
var result : Int[];
result = [];
let cubeNumList : Int[] = [ 0 , 1, 2*2*2, 3*3*3, 4*4*4, 5*5*5, 6*6*6, 7*7*7, 8*8*8, 9*9*9];
let pNumList : Int[] = [ 0 , 100, 200, 300, 400, 500, 600, 700, 800, 900];
import Foundation
//
// e.g.
// x[] = {3,6,2,1,4,5,2}
// head : 首和 : 3, 9, 11, 12, 16, 21, 23
// tail : 尾和 : 2, 7, 11, 12, 14, 20, 23
// 相同, 11, 12, 23, 共三組
func headtail(x : Int[]) -> Int
import Foundation
//
// e.g.
// f[] = {1, 3, 5, 7, 9}
// g[] = {2, 6, 8}
// | f[] - g[] | 最小的一個
// result = 1
func mindist(f : Int[], g : Int[]) -> Int
{