본문 바로가기

분류 전체보기816

Grasshopper - Terminal game move function Terminal game move function In this game, the hero moves from left to right. The player rolls the dice and moves the number of spaces indicated by the dice two times. In SQL, you will be given a table moves with columns position and roll. Return a table which uses the current position of the hero and the roll (1-6) and returns the new position in a column res. Example: move(3, 6) should equal 15.. 2022. 5. 29.
Easy SQL: Cube Root and Natural Log Given the following table 'decimals': ** decimals table schema ** id number1 number2 Return a table with two columns (cuberoot, logarithm) where the values in cuberoot are the cube root of those provided in number1 and the values in logarithm are changed to the natural logarithm of those in number2. Solution: SELECT CBRT(number1) as cuberoot, LN(number2) as logarithm FROM decimals The cube root .. 2022. 5. 27.
심플 팩토리 패턴 팩토리 패턴 개요 팩토리란, 다른 클래스의 객체를 생성하는 클래스를 일컫는다. 클라이언트는 특정 ‘인자’와 함께 ‘메서드’를 호출하고 팩토리는 해당 객체를 생성하고 반환한다. 직접 객체를 생성하지 않고 팩토리를 사용하는 이유 객체 생성과 클래스 구현을 나눠 상호 의존도를 줄이기 위함. 클라이언트는 인터페이스와 메소드, 인자 등의 정보만 있으면 된다. 코드를 수정하지 않고 팩토리에 새로운 클래스를 추가할 수 있다. 이미 생성된 객체를 팩토리가 재활용할 수 있다. 팩토리 패턴 3가지 종류 심플 팩토리 패턴 - 인터페이스는 객체 생성 로직을 숨기고 객체를 생성 팩토리 메소드 패턴 - 인터페이스를 통해 객체를 생성하지만 서브 클래스가 객체 생성에 필요한 클래스를 선택 추상 팩토리 패턴 - 객체 생성에 필요한 클.. 2022. 5. 27.
Grasshopper - Check for factor This function should test if the factor is a factor of base. Return true if it is a factor or false if it is not. About factors Factors are numbers you can multiply together to get another number. 2 and 3 are factors of 6 because: 2 * 3 = 6 You can find a factor by dividing numbers. If the remainder is 0 then the number is a factor. You can use the mod operator (%) in most languages to check for.. 2022. 5. 26.
SQL Basics: Maths with String Manipulations Given a demographics table in the following format: demographics table schema id name birthday race return a single column named calculation where the value is the bit length of name, added to the number of characters in race. Solution: SELECT BIT_LENGTH(name)+ CHAR_LENGTH(race) AS calculation FROM demographics 'BIT_LENGTH' can obtain the bit length. 'CHAR_LENGTH' or 'LENGTH' can obtain the char.. 2022. 5. 25.
모노스테이트, 메타클래스, 싱글톤 구현예시 모노스테이트 싱글톤 패턴 The Monostate Singleton Pattern 객체 생성여부 보다는 상태와 행위에 초점을 맞춘 패턴 단일 객체가 아닌, 모든 객체가 같은 상태를 공유하는 패턴 __init__ 으로 구현 하는 방법 # __init__ 으로 구현하는 방법 class Mono: __shared_state = {"공유":"데이터"} def __init__(self): self.data = 1 self.__dict__ = self.__shared_state pass obj = Mono() obj.data = 9999 other_obj = Mono() print(f"{obj=}") print(f"{other_obj=}") """ 결과값. 서로 다른 인스턴스임을 확인할 수 있음 obj= other.. 2022. 5. 25.