Skip to content

Commit

Permalink
Add first exercise: Hello world (#6)
Browse files Browse the repository at this point in the history
* add key_features

* update gitignore with Cairo-specific files

* add hello-world exercise + format config.json

* update key_features to include 6 items

* Create strings concept

---------

Co-authored-by: Nenad <nenad@better.giving>
  • Loading branch information
Nenad Misić and Nenad committed Jun 18, 2024
1 parent a5e011c commit 8f02b41
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.DS_Store
bin/configlet
bin/configlet.exe
**/target
exercises/*/*/Scarb.lock
7 changes: 7 additions & 0 deletions concepts/strings/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"blurb": "ByteArray is a sequence of ASCII characters longer than 31 characters, written using double quotes",
"authors": [
"misicnenad"
],
"contributors": []
}
1 change: 1 addition & 0 deletions concepts/strings/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# String
3 changes: 3 additions & 0 deletions concepts/strings/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Introduction

In Cairo, there's no native type for strings. Instead, you can use a single `felt252` to store a short string of up to 31 characters, or a `ByteArray` for strings of arbitrary length. Short strings use single quotes and `ByteArray` uses double quotes. All characters must follow the ASCII standard.
14 changes: 14 additions & 0 deletions concepts/strings/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"url": "https://book.cairo-lang.org/ch02-02-data-types.html#string-types",
"description": "String types in the Cairo book"
},
{
"url": "https://starknet-by-example.voyager.online/getting-started/basics/bytearrays-strings.html",
"description": "Starknet by Example section on Strings and ByteArrays"
},
{
"url": "https://docs.starknet.io/architecture-and-concepts/smart-contracts/serialization-of-cairo-types/#serialization_of_byte_arrays",
"description": "Starknet docs explaining how ByteArray is implemented and how it's serialized"
}
]
68 changes: 59 additions & 9 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,72 @@
]
},
"exercises": {
"concept": [],
"practice": []
"practice": [
{
"slug": "hello-world",
"name": "Hello World",
"uuid": "1a0e23d9-e8f9-493a-af46-2be040173b64",
"practices": [
"strings"
],
"prerequisites": [],
"difficulty": 1,
"topics": [
"test_driven_development"
]
}
]
},
"concepts": [],
"key_features": [],
"concepts": [
{
"uuid": "4eb800f7-f6c5-4b28-8492-229b6a51829e",
"slug": "strings",
"name": "Strings"
}
],
"key_features": [
{
"title": "Developer-friendly",
"content": "Write Rust-like code and generate proofs for program execution - math isn't a barrier.",
"icon": "easy"
},
{
"title": "Provable",
"content": "Produces provable programs, making it possible to compute trustworthy values on untrusted machines.",
"icon": "safe"
},
{
"title": "Efficient",
"content": "Cairo compiles down to an ad-hoc assembly engineered specifically for efficient proof generation.",
"icon": "fast"
},
{
"title": "Immutable",
"content": "Cairo uses the immutable memory model, improving data integrity and security.",
"icon": "immutable"
},
{
"title": "General purpose",
"content": "From onchain gaming to provable ML, Cairo makes building trustless applications possible.",
"icon": "general-purpose"
},
{
"title": "Innovative",
"content": "Cairo is a fast-growing language that keeps delivering new and exciting features to its developers.",
"icon": "evolving"
}
],
"tags": [
"execution_mode/compiled",
"paradigm/functional",
"paradigm/imperative",
"paradigm/procedural",
"typing/static",
"typing/strong",
"execution_mode/compiled",
"platform/windows",
"platform/mac",
"platform/linux",
"platform/mac",
"platform/windows",
"runtime/standalone_executable",
"typing/static",
"typing/strong",
"used_for/artificial_intelligence",
"used_for/backends",
"used_for/financial_systems",
Expand Down
16 changes: 16 additions & 0 deletions exercises/practice/hello-world/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Instructions

The classical introductory exercise.
Just say "Hello, World!".

["Hello, World!"][hello-world] is the traditional first program for beginning programming in a new language or environment.

The objectives are simple:

- Modify the provided code so that it produces the string "Hello, World!".
- Run the test suite and make sure that it succeeds.
- Submit your solution and check it at the website.

If everything goes well, you will be ready to fetch your first real exercise.

[hello-world]: https://en.wikipedia.org/wiki/%22Hello,_world!%22_program
20 changes: 20 additions & 0 deletions exercises/practice/hello-world/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"authors": [
"misicnenad"
],
"files": {
"solution": [
"src/lib.cairo",
"Scarb.toml"
],
"test": [
"src/tests.cairo"
],
"example": [
".meta/example.cairo"
]
},
"blurb": "Exercism's classic introductory exercise. Just say \"Hello, World!\".",
"source": "This is an exercise to introduce users to using Exercism",
"source_url": "https://en.wikipedia.org/wiki/%22Hello,_world!%22_program"
}
3 changes: 3 additions & 0 deletions exercises/practice/hello-world/.meta/example.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn hello() -> ByteArray {
"Hello, World!"
}
13 changes: 13 additions & 0 deletions exercises/practice/hello-world/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[af9ffe10-dc13-42d8-a742-e7bdafac449d]
description = "Say Hi!"
4 changes: 4 additions & 0 deletions exercises/practice/hello-world/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "hello_world"
version = "0.1.0"
edition = "2023_11"
7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// ByteArray is a string that's not limited to 31 characters, you'll learn more about this later
fn hello() -> ByteArray {
"Goodbye, Mars!"
}

#[cfg(test)]
mod tests;
4 changes: 4 additions & 0 deletions exercises/practice/hello-world/src/tests.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test_hello_world() {
assert_eq!(hello_world::hello(), "Hello, World!");
}

0 comments on commit 8f02b41

Please sign in to comment.