Skip to content

Instantly share code, notes, and snippets.

@ishankhare07
Created May 26, 2017 11:47
Show Gist options
  • Save ishankhare07/5436d0221c885278d3486da7be5d1f1e to your computer and use it in GitHub Desktop.
Save ishankhare07/5436d0221c885278d3486da7be5d1f1e to your computer and use it in GitHub Desktop.
star pattern
-module(star_pattern).
-export([print/2]).
for(N, N, Symbol) -> io:format("~s", [Symbol]);
for(X, N, Symbol) ->
io:format("~s",[Symbol]),
for(X, N-1, Symbol).
print(Symbol, Times) ->
start_print(Symbol, 1, Times).
start_print(Symbol, Times, Times) ->
for(1, Times, Symbol);
start_print(Symbol, Current, Times) ->
for(1, Current, Symbol),
io:format("~n"),
start_print(Symbol, Current+1, Times).
@ishankhare07
Copy link
Author

$ erl
Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V8.3  (abort with ^G)
1> c(star_pattern).
{ok,star_pattern}
2> star_pattern:print('*', 5).
*
**
***
****
*****ok
3>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment