1. Home
  2. /
  3. Hack
  4. /
  5. Prime Checker

Prime Checker - Hack Typing CST Test

Loading…

Prime Checker — Hack Code

Checks if a number is prime.

<?hh
function isPrime(int $n): bool {
	if ($n < 2) return false;
	for ($i = 2; $i < $n; $i++) {
		if ($n % $i === 0) return false;
	}
	return true;
}
<<__EntryPoint>>
function main(): void {
	echo isPrime(13) ? "Prime\n" : "Not Prime\n";
}

Hack Language Guide

Hack is a programming language developed by Facebook as a dialect of PHP. It adds static typing, enhanced performance, and modern programming features while maintaining compatibility with PHP, enabling rapid development of large-scale web applications.

Primary Use Cases

  • ▸Large-scale web application development
  • ▸Maintaining and modernizing PHP codebases
  • ▸Developing scalable backend services
  • ▸Improving code safety with static typing
  • ▸Rapid iteration and prototyping in web projects

Notable Features

  • ▸Optional static typing for safety and performance
  • ▸Type inference to reduce boilerplate
  • ▸Compatibility with PHP codebases
  • ▸Collections and async support
  • ▸Generics and shape types for advanced type modeling

Origin & Creator

Developed by Facebook in 2014.

Industrial Note

Hack is mainly used for large-scale web applications, especially for projects requiring high performance, maintainability, and gradual typing within PHP-based systems.

More Hack Typing Exercises

Hack Counter and Theme ToggleHack Fibonacci SequenceHack Factorial CalculatorHack Sum of ArrayHack Reverse StringHack Multiplication TableHack Celsius to FahrenheitHack Simple Alarm SimulationHack Random Walk Simulation

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher