Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "ExecuteTime": {
- "end_time": "2018-07-22T19:24:21.756000+09:00",
- "start_time": "2018-07-22T10:24:19.493Z"
- }
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Julia Version 0.6.4\n",
- "Commit 9d11f62bcb (2018-07-09 19:09 UTC)\n",
- "Platform Info:\n",
- " OS: macOS (x86_64-apple-darwin14.5.0)\n",
- " CPU: Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz\n",
- " WORD_SIZE: 64\n",
- " BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell MAX_THREADS=16)\n",
- " LAPACK: libopenblas64_\n",
- " LIBM: libopenlibm\n",
- " LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)\n"
- ]
- }
- ],
- "source": [
- "versioninfo()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {
- "ExecuteTime": {
- "end_time": "2018-07-22T19:24:23.585000+09:00",
- "start_time": "2018-07-22T10:24:23.004Z"
- }
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "calc (generic function with 1 method)"
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "function calc(x, y, z)\n",
- " if z > 5\n",
- " throw(ArgumentError(\"z ($z) must to be ≤ 5.\"))\n",
- " end\n",
- " x + y * z\n",
- "end"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {
- "ExecuteTime": {
- "end_time": "2018-07-22T19:24:24.529000+09:00",
- "start_time": "2018-07-22T10:24:24.424Z"
- }
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "calc_z (generic function with 1 method)"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "function calc_z(n)\n",
- " x = 0\n",
- " y = 3\n",
- " z = 0\n",
- " try\n",
- " while calc(0, 3, z) < n\n",
- " z += 1\n",
- " end\n",
- " catch ex\n",
- " if ex isa ArgumentError\n",
- " # pass\n",
- " else\n",
- " rethrow()\n",
- " end\n",
- " end \n",
- " z - 1\n",
- "end"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {
- "ExecuteTime": {
- "end_time": "2018-07-22T19:24:25.519000+09:00",
- "start_time": "2018-07-22T10:24:25.344Z"
- }
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "3"
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "calc_z(10)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "ExecuteTime": {
- "end_time": "2018-07-22T19:24:26.127000+09:00",
- "start_time": "2018-07-22T10:24:26.124Z"
- }
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "5"
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "calc_z(20)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Julia 0.6.4",
- "language": "julia",
- "name": "julia-0.6"
- },
- "language_info": {
- "file_extension": ".jl",
- "mimetype": "application/julia",
- "name": "julia",
- "version": "0.6.4"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment