Skip to content

Instantly share code, notes, and snippets.

View DPS0340's full-sized avatar

Jiho Lee DPS0340

View GitHub Profile
@DPS0340
DPS0340 / FizzBuzz.scala
Created August 1, 2019 03:39
FizzBuzz Scala
def FizzBuzz(n: Int, rules: List[Int], says: List[String]): Unit = {
def checker(rule: Int, say: String): (Int) => String = (k: Int) => if(k % rule == 0) say else ""
val guards = (for {
i <- 0 until rules.length
} yield checker(rules(i), says(i))).toList
def stringGen(k: Int, gs: List[(Int) => String]): String = if(!gs.isEmpty) gs.head(k) + stringGen(k, gs.tail) else ""
for (i <- 1 to n) {
val s = stringGen(i, guards)
if(s != "") println(s)
else println(i)
@DPS0340
DPS0340 / gugu.scala
Created August 1, 2019 03:41
tailrec times table scala
import scala.annotation.tailrec
def gugu(max: Int): Unit = {
@tailrec
def go(i:Int, j:Int): Unit = {
if(i > max) return
else if(j > max) return go(i+1, 1)
else {
println("%d * %d = %d".format(i, j, i*j))
go(i, j+1)
@DPS0340
DPS0340 / leapyear.scala
Created August 1, 2019 03:41
leap year scala
for (year <- 1999 to 2019 if year % 4 == 0 if ((year % 100 != 0) || (year % 400 == 0))) println(year)
@DPS0340
DPS0340 / rot13.scala
Created August 1, 2019 03:42
rot13 scala
def rot13(s: String) = s.map(x => x match {
case c if 'A' to 'Z' contains c => ('A' to 'Z')(((c.toInt - 'A') + 13) % 26)
case z if 'a' to 'z' contains z => ('a' to 'z')(((z.toInt - 'a') + 13) % 26)
case other => other
})
println(rot13("Hello World!!!!!!!")) // Uryyb Jbeyq!!!!!!!
@DPS0340
DPS0340 / qsort.scala
Created August 1, 2019 03:42
quick sort scala
def qsort(lst: List[Int]): List[Int] = lst match {
case Nil => Nil
case x :: xs => qsort(xs.filter(_ <= x)) ::: List(x) ::: qsort(xs.filter(_ > x))
}
println(qsort(List(15, 3, 6, 7, 9, 1))) // List(1, 3, 6, 7, 9, 15)
import java.io._
import java.math._
import java.security._
import java.text._
import java.util._
import java.util.concurrent._
import java.util.function._
import java.util.regex._
import java.util.stream._
import java.io._
import java.math._
import java.security._
import java.text._
import java.util._
import java.util.concurrent._
import java.util.function._
import java.util.regex._
import java.util.stream._
@DPS0340
DPS0340 / main.py
Created October 29, 2019 19:00
ideone download script
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# download chromedriver to source code path
# python main.py
def login():
driver.get("https://ideone.com")
driver.find_element_by_class_name("icon-signin").find_element_by_xpath("..").click()
@DPS0340
DPS0340 / hhhij.c
Last active January 31, 2020 18:32
hhhij
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <malloc.h>
typedef struct _student {
int number;
int score[3];
int sum;
double avg;
@DPS0340
DPS0340 / .emacs
Created March 31, 2020 03:58
emacs setting
; (dolist (char-regexp alist)
; (set-char-table-range composition-function-table (car char-regexp)
; `([,(cdr char-regexp) 0 font-shape-gstring]))))
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.