{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Hopfstader's functions are defined as below. Can we find a pattern? From a Tweet [insert link] " ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "using PyPlot" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "H (generic function with 1 method)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "F(n) = n==0 ? 0 : n - F(n-1)\n", "G(n) = n==0 ? 0 : n - G(G(n-1))\n", "H(n) = n==0 ? 0 : n - H(H(H(n-1)))\n", "\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "ename": "BoundsError", "evalue": "BoundsError: attempt to access 121-element Array{Int64,1} at index [0]", "output_type": "error", "traceback": [ "BoundsError: attempt to access 121-element Array{Int64,1} at index [0]", "", "Stacktrace:", " [1] getindex(::Array{Int64,1}, ::Int64) at ./array.jl:729", " [2] (::getfield(Main, Symbol(\"##11#12\")))(::Int64) at ./none:0", " [3] iterate at ./generator.jl:47 [inlined]", " [4] collect_to!(::Array{Int64,1}, ::Base.Generator{UnitRange{Int64},getfield(Main, Symbol(\"##11#12\"))}, ::Int64, ::Int64) at ./array.jl:651", " [5] collect_to_with_first!(::Array{Int64,1}, ::Int64, ::Base.Generator{UnitRange{Int64},getfield(Main, Symbol(\"##11#12\"))}, ::Int64) at ./array.jl:630", " [6] collect(::Base.Generator{UnitRange{Int64},getfield(Main, Symbol(\"##11#12\"))}) at ./array.jl:611", " [7] top-level scope at util.jl:156", " [8] top-level scope at In[11]:2" ] } ], "source": [ "x = 0:120\n", "#f = [F(n) - F(n-1) for n in x]\n", "#g = [G(n) - G(n-1) for n in x]\n", "@time h = [n==0 ? 0 : n - h[h[h[n]]] for n in x]\n", "#plot(x,h,hs)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for i in 1:50\n", " for k in 1:200 - i\n", " if h[i] != h[i+k]\n", " print(\"Not \", i)\n", " break\n", " end\n", " end\n", "end\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.1.0", "language": "julia", "name": "julia-1.1" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.1.0" } }, "nbformat": 4, "nbformat_minor": 2 }