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
// 스칼라의 문법인 케이스 클래스와 패턴 매칭 코드로 살펴보기 | |
// regular, non-encapsulated data structures 가 필요할 때 케이스 클래스 사용 | |
// Programming In Scala 15장 예제 코드로 구성 됨 | |
abstract class Expr | |
case class Var(name: String) extends Expr | |
case class Number(num: Double) extends Expr | |
case class UnOp(operator: String, arg: Expr) extends Expr | |
case class BinOp(operator: String, left: Expr, right: Expr) extends Expr |
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
case class Dummy(a: Int, b: Double) | |
val obj1 = Dummy(1, 10.0) | |
val obj2 = Dummy(2, 20.0) | |
val obj3 = Dummy(1, 10.0) | |
obj1 == obj2 | |
obj1 equals obj2 | |
obj1 == obj3 |
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 EqualTest{ | |
public static void main(String []args){ | |
new EqualTest().test(); | |
} | |
private void test() { | |
Dummy obj1 = new Dummy(1, 10.0); | |
Dummy obj2 = new Dummy(2, 20.0); | |
Dummy obj3 = new Dummy(1, 10.0); | |
System.out.println("obj1 == obj2: " + (obj1 == obj2) + " / obj1.equals(obj2): " + obj1.equals(obj2) ); |
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
int _twoExponential(int exponent, int acc) { | |
if ( exponent == 0 ) { | |
return acc; | |
} | |
acc *= 2; | |
return _twoExponential(--exponent, acc); | |
} | |
int exponential(int num) { |
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
package nfm.ex06 | |
/** | |
* Programming In Scala 2/e List 6.5 코드 | |
* 분수 Class | |
* @param n 분자 | |
* @param d 분모 | |
*/ | |
/* 스칼라에 있는 문법: Class에서 기본 생성자 선언 가능 |
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
float tempC; | |
int reading; | |
int tempPin = 0; | |
void setup() | |
{ | |
Serial.begin(9600); | |
analogReference(INTERNAL); | |
} | |
void loop() | |
{ |
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
//Arduino Sample Code for SHT1x Humidity and Temperature Sensor | |
//www.DFRobot.com | |
//Version 1.0 | |
#include <SHT1x.h> | |
// Specify data and clock connections and instantiate SHT1x object | |
#define dataPin 10 | |
#define clockPin 11 | |
SHT1x sht1x(dataPin, clockPin); |
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
# coding: utf-8 | |
from xlwt import Workbook | |
book = Workbook() | |
sheet1 = book.add_sheet(u'Ex Sheet1') | |
sheet2 = book.add_sheet(u'Ex Sheet2') | |
sheet1.write(0,0, u'Name') | |
sheet1.write(0,1, u'Sex') |
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
# coding: utf-8 | |
from xlrd import open_workbook | |
wb = open_workbook('simple.xls') | |
for sheet in wb.sheets(): | |
print(u'Sheet:' + sheet.name) | |
print("Number of Sheets: " + str(wb.nsheets)) |
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
def factorial(n: Int): Int = { | |
def loop(acc: Int, n: Int): Int = | |
if (n == 0) acc | |
else loop(acc*n, n-1) | |
loop(1, n) | |
} |