Posts

Showing posts from January, 2025

Simple Recursion Function

Function Calculator Let's create a logic to calculate the population after y years, given an initial population of n people and an annual growth rate of r%. The logic can be expressed with the following formula: (Population in year y) = (1+r/100)*(Population in year y-1) (Population in year 0) = n In the first line above, the population in year y represents the population we want to know, and the population in year (y-1) means the population of the previous year. Therefore, it means that the population in a given year is the previous year's population increased by r%, or r/100, and this calculation is (1+r/100) * previous year's population. The second line, population in year 0, means the initial population. The above expression can be converted into code that a computer can understand as follows: def population(y,n,r)=(1+r/100)*population(y-1,n,r); population(0,n,r)= n; You can see that only the variable y changes, while the other variables n and r are constants. ...

Function Examples

Daily life functions Convert weight in grams to weight in ounces. def gramsToOunces(g)=g*0.0353;    Convert weight in ounces to weight in grams. def ouncesToGrams(o)=o*28.35; Convert Celsius temperature to Fahrenheit temperature   def CelsiusToFahrenheit(c)=c*9/5+32;   Convert Fahrenheit temperature to Celsius temperature def FahrenheitToCelsius(f)=(f-32)*5/9; Convert length in centimeters to length in inches   def centimetersToInches(c)=c*0.3937;   Convert length in inches to length in centimeters def inchesToCentimeters(i)=i*2.54; Mathematic functions Number 'n' is prime number? def isPrime(n) {     if (n <= 1) {         return false;     }     var i = 2;     while (i * i <= n) {         if (n % i == 0) {             return false;         }         i = i + 1;     }     return true; ...

Bug Report

If you find any bug in the calculator please let me know. Thank you. Testing. .  . def catalan(n){   if(n<=1){     return 1;   }   var result=0;   for(var i=0;i<n;i=i+1){     var a=catalan(i);     var b=catalan(n−i−1);     result=result+a*b;   }   return result; } Result: Ok 2025.3.7. Testing. . . def catalan4(n){   if(n<=1){     return 1;   }   var result=0;   for(var i=0;i<n;i=i+1){     var x=n−1−i;     var a=catalan4(i);     var b=catalan4(x);     var c=a*b;     result=result+c;   }   return result; } Result: OK 2025.3.7. Testing... def catalan5(n){   if(n<=1){     return 1;   }   var result=0;   for(var i=0;i<n;i=i+1){     var x=n−1−i;     var a=catalan5(i);     var b=catalan5(x);     var c=a*b;     result=result+c;   }...

함수계산기 코딩하기

Image
  함수계산기 는 사칙연산을 계산하는 기능 뿐만 아니라 자바스크립트와 비슷한 코드를 사용해 자신만의 함수를 만들어 계산에 사용할 수 있는 강력한 계산기입니다. 이 계산기에 사용되는 스크립트 이름은 SimpleMath 라 이름 붙였습니다. 여기서는 어떻게 함수계산기 에서 SimpleMath를 사용하여 코딩을 하는지 코딩하는 법을 설명합니다. 함수 만들기 함수계산기 공장페이지를 열어서 코딩을 하고 run버튼을 누르면 코딩을 실행시킬 수 있습니다. 함수계산기에서는 다음과 같은 두가지 형태로 함수를 만들 수 있습니다. def 함수이름(파라미터)=수식; def 함수이름(파라미터){실행코드} 이상 두가지 형태 중 가장 쉬운 첫번째 형태를 우선 살펴보겠습니다. 가령 두 수를 더하는 함수를 만든다고 가정합시다. 함수이름을 두수합 이라 놓고 두 개의 실제  들어갈 값을 대신할 파라미터를 수1,수2라 이름 붙여서 다음과 같이 정의할 수 있습니다. def 두수합(수1,수2)=수1+수2; 일반 수식을 써서 함수를 정의한 형태입니다. 우선 def라는 키워드를 먼저 표기함으로써 새로운 함수를 정의함을 계산기 시스템인 SimpleMath에게 알려 주어야합니다. 그 다음엔 적당한 함수이름을 붙여줍니다. 여기서는 두수합이라 이름붙였습니다. 함수이름은 지구상에 어떤 언어글자로도 만들 수 있습니다. 다만 함수계산기에서 허용하는 이름의 규칙은 언제나 문자가 먼저오고 숫자를 이름에 붙일 경우 숫자는 문자보다 항상 뒤에 와야 합니다.이름 사이에 공백이 있어서는 안되고 또 흔히 쓰이는 _는 계산기 코딩시스템인 SimpleMath에서는 허용하지 않습니다. 아래는 함수이름의 사용 예 입니다. 두수합 -> OK 두수합12 -> OK 두수 합 ->  NO 두수_합 ->  NO 두수12합 ->  NO twoSum -> OK twoSum12-> OK two sum -> NO two12Sum -> NO two_sum -...

SimpleMath Script Tutorial

  SimpleMath Script Tutorial Welcome to the SimpleMath Script tutorial! This guide will help you learn the basics of our programmable calculator script, which has a syntax similar to JavaScript but is simplified to support only number and boolean types. Variables Declare variables using the 'var' keyword: var x; var y = 5 ; Assign values to variables: x = y; x = 3 + y ; Data Types SimpleMath supports two data types: Numbers: Any numeric value Booleans: true or false Types are inferred, not specified. Operators SimpleMath supports the following operators: + : 2 + 1 -> 3 - : 2 - 1 -> 1 * : 2 * 3 -> 6 (multiplication) / : 4 / 2 -> 2 (division) ^ : 2 ^ 3 -> 8 (exponentiation) % : 3 % 2 -> 1 (remainder) = : var num1 = 1; var num2 = 2; (assignment) num1 + num2 -> 3 == : 3 == 3 (3 equals 3) -> true 3 == 2 (3 equals 2) -> false != : 3 != 2 (3 is not equal to 2) -> true 3 != 3 (3 is not equal to 3)-> false < : 2 < 3 (2...

Prompt for AI

  SimpleMath Script SimpleMath is a programming script with a syntax similar to JavaScript, but extremely simplified to support only number and boolean types. SimpleMath is to be used only for Function Calculator . Here are the key features and rules: Variables Declare variables using the 'var' keyword: var a; var b = 3; Assign values to variables: a = b; a = 3 + b; Variables follow strict scope rules similar to java. Variable should be declared first using 'var' keyword. Without decalaration it can not be used. Data Types Only two data types: number and boolean Types are inferred, not specified Number literals: Any numeric value Boolean literals: true or false Collection data structures such as array or list are not supported. Only single data type number and boolean are supported. SimpleMath does not have "null" or "undefined" unlike javascript. When null or undefined value needs to be returned in a function you can return very unlikely number such...