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
class Euler7 { | |
val primeStream: Stream[Int] = 2 #:: 3 #:: primeStream.tail.map(m => nextPrime(m)) | |
def nthPrime(index: Int) = primeStream(index - 1) | |
def isPrime(num: Int) = { | |
(2 until num).forall(num % _ != 0) | |
} |
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
class Euler4 { | |
def findMaxPalindrome():Int = { | |
for (i <- (1 to 9).reverse; j <- (0 to 9).reverse; k <- (0 to 9).reverse) { | |
val num = 100001 * i + 10010 * j + 1100 * k | |
for (k <- (100 to Math.sqrt(num).toInt).reverse if num % k == 0 && num / k < 1000) { | |
return num | |
} | |
} | |
return 0 | |
} |
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
class Euler6 { | |
def squareSum(maxNum:Int) = (1 to maxNum).map( num => num * num).sum | |
def sumSquare(maxNum:Int) = { | |
val sum = (maxNum * (maxNum+1) /2) | |
sum * sum | |
} | |
def diff(maxNum:Int) = Math.abs(squareSum(maxNum) - sumSquare(maxNum)) |
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
class Euler8 { | |
val rawData = "73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557668966489504452445231617318564030987111217223831136222989342338030813533627661428280644448664523874930358907296290491560440772390713810515859307960866701724271218839987979087922749219016997208880937766572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224137565705605749026140797296865241453510047482166370484403199890008895243450658541227588666881164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760605886116467109405077541002256983155200055935729725716362695618826704282524836008232575304207 |
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
class Euler9 { | |
def getPitagorasWithSum1000(): (Int, Int, Int) = { | |
//if c > a > b then a > 1000/3 and a < 1000/2 | |
for (a <- 333 to 499; b <- (500 - a to a - 1) if a * a + b * b == (1000 - a - b) * (1000 - a - b)) { | |
return (a, b, 1000 - a - b) | |
} | |
return (0, 0, 0) | |
} | |
def calcMult() = { |
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
class Euler5 { | |
def isPrime(num: Int) = { | |
(2 until num).forall(num % _ != 0) | |
} | |
/** | |
* 숫자 n의 unique한 소인수 집합 | |
* @param num | |
* @param fractions | |
* @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
private final static String PATTERN_COLOR_REGEXP = "(<color=(.+?)>)(.+?)(</color>)"; | |
private final static Pattern PATTERN_COLOR = Pattern.compile(PATTERN_COLOR_REGEXP); | |
private final static String PATTERN_BOLD_REGEXP = "(<b>)(.+?)(</b>)"; | |
private final static Pattern PATTERN_BOLD = Pattern.compile(PATTERN_BOLD_REGEXP); | |
private final static String PATTERN_UNDERLINE_REGEXP = "(<u>)(.+?)(</u>)"; | |
private final static Pattern PATTERN_UNDERLINE = Pattern.compile(PATTERN_UNDERLINE_REGEXP); | |
/** |
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
public void pushFragments(String tag, Fragment fragment, | |
boolean shouldAnimate, boolean shouldAdd) { | |
if (shouldAdd) | |
mStacks.get(tag).push(fragment); | |
FragmentManager manager = getSupportFragmentManager(); | |
FragmentTransaction ft = manager.beginTransaction(); | |
ft.replace(R.id.realtabcontent, fragment).addToBackStack(null); | |
ft.commit(); | |
} |
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
public class WebViewActivity extends Activity { | |
WebView wv; | |
LinkedList<JsResult> jsResults = new LinkedList<>(); | |
@TargetApi(Build.VERSION_CODES.KITKAT) | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_wv); |
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
fun main(args: Array<String>) { | |
fun getMap(arg1: Array<Int>, arg2: Array<Int>) = | |
arg1.mapIndexed { index, v -> (v or arg2[index]).toString(2) } | |
.map { | |
it.map { if (it == '1') '#' else ' ' } | |
.toCharArray().joinToString(prefix = "\"", postfix = "\"", separator = "") | |
} | |
println(getMap(arrayOf(9, 20, 28, 18, 11), arrayOf(30, 1, 21, 17, 28))) | |
println(getMap(arrayOf(46, 33, 33, 22, 31, 50), arrayOf(27, 56, 19, 14, 14, 10))) |