Guest User

Untitled

a guest
Jul 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {
  7. "ExecuteTime": {
  8. "end_time": "2018-07-22T19:24:21.756000+09:00",
  9. "start_time": "2018-07-22T10:24:19.493Z"
  10. }
  11. },
  12. "outputs": [
  13. {
  14. "name": "stdout",
  15. "output_type": "stream",
  16. "text": [
  17. "Julia Version 0.6.4\n",
  18. "Commit 9d11f62bcb (2018-07-09 19:09 UTC)\n",
  19. "Platform Info:\n",
  20. " OS: macOS (x86_64-apple-darwin14.5.0)\n",
  21. " CPU: Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz\n",
  22. " WORD_SIZE: 64\n",
  23. " BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell MAX_THREADS=16)\n",
  24. " LAPACK: libopenblas64_\n",
  25. " LIBM: libopenlibm\n",
  26. " LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)\n"
  27. ]
  28. }
  29. ],
  30. "source": [
  31. "versioninfo()"
  32. ]
  33. },
  34. {
  35. "cell_type": "code",
  36. "execution_count": 2,
  37. "metadata": {
  38. "ExecuteTime": {
  39. "end_time": "2018-07-22T19:24:23.585000+09:00",
  40. "start_time": "2018-07-22T10:24:23.004Z"
  41. }
  42. },
  43. "outputs": [
  44. {
  45. "data": {
  46. "text/plain": [
  47. "calc (generic function with 1 method)"
  48. ]
  49. },
  50. "execution_count": 2,
  51. "metadata": {},
  52. "output_type": "execute_result"
  53. }
  54. ],
  55. "source": [
  56. "function calc(x, y, z)\n",
  57. " if z > 5\n",
  58. " throw(ArgumentError(\"z ($z) must to be ≤ 5.\"))\n",
  59. " end\n",
  60. " x + y * z\n",
  61. "end"
  62. ]
  63. },
  64. {
  65. "cell_type": "code",
  66. "execution_count": 3,
  67. "metadata": {
  68. "ExecuteTime": {
  69. "end_time": "2018-07-22T19:24:24.529000+09:00",
  70. "start_time": "2018-07-22T10:24:24.424Z"
  71. }
  72. },
  73. "outputs": [
  74. {
  75. "data": {
  76. "text/plain": [
  77. "calc_z (generic function with 1 method)"
  78. ]
  79. },
  80. "execution_count": 3,
  81. "metadata": {},
  82. "output_type": "execute_result"
  83. }
  84. ],
  85. "source": [
  86. "function calc_z(n)\n",
  87. " x = 0\n",
  88. " y = 3\n",
  89. " z = 0\n",
  90. " try\n",
  91. " while calc(0, 3, z) < n\n",
  92. " z += 1\n",
  93. " end\n",
  94. " catch ex\n",
  95. " if ex isa ArgumentError\n",
  96. " # pass\n",
  97. " else\n",
  98. " rethrow()\n",
  99. " end\n",
  100. " end \n",
  101. " z - 1\n",
  102. "end"
  103. ]
  104. },
  105. {
  106. "cell_type": "code",
  107. "execution_count": 4,
  108. "metadata": {
  109. "ExecuteTime": {
  110. "end_time": "2018-07-22T19:24:25.519000+09:00",
  111. "start_time": "2018-07-22T10:24:25.344Z"
  112. }
  113. },
  114. "outputs": [
  115. {
  116. "data": {
  117. "text/plain": [
  118. "3"
  119. ]
  120. },
  121. "execution_count": 4,
  122. "metadata": {},
  123. "output_type": "execute_result"
  124. }
  125. ],
  126. "source": [
  127. "calc_z(10)"
  128. ]
  129. },
  130. {
  131. "cell_type": "code",
  132. "execution_count": 5,
  133. "metadata": {
  134. "ExecuteTime": {
  135. "end_time": "2018-07-22T19:24:26.127000+09:00",
  136. "start_time": "2018-07-22T10:24:26.124Z"
  137. }
  138. },
  139. "outputs": [
  140. {
  141. "data": {
  142. "text/plain": [
  143. "5"
  144. ]
  145. },
  146. "execution_count": 5,
  147. "metadata": {},
  148. "output_type": "execute_result"
  149. }
  150. ],
  151. "source": [
  152. "calc_z(20)"
  153. ]
  154. },
  155. {
  156. "cell_type": "code",
  157. "execution_count": null,
  158. "metadata": {},
  159. "outputs": [],
  160. "source": []
  161. }
  162. ],
  163. "metadata": {
  164. "kernelspec": {
  165. "display_name": "Julia 0.6.4",
  166. "language": "julia",
  167. "name": "julia-0.6"
  168. },
  169. "language_info": {
  170. "file_extension": ".jl",
  171. "mimetype": "application/julia",
  172. "name": "julia",
  173. "version": "0.6.4"
  174. }
  175. },
  176. "nbformat": 4,
  177. "nbformat_minor": 2
  178. }
Add Comment
Please, Sign In to add comment