Sonnet Primes in Python
A while back I wrote about sonnet primes, primes of the form. ababcdcdefefgg where the letters a through g represent digits and a is not zero. The name comes from the rhyme scheme of an English (Shakespearean) sonnet.
In the original post I gave Mathematica code to find all sonnet primes. This post shows how to do it in Python.
from itertools import permutations
def number(t):
# turn a tuple into a number
return 10100000000000*t[0] + 1010000000000*t[1] \
+ 1010000000*t[2] + 101000000*t[3] \
+ 101000*t[4] + 10100*t[5] \
+ 11*t[6]
sonnet_numbers = (number(t) for t in
permutations(range(10), 7) if t[0] != 0)
sonnet_primes = filter(isprime, sonnet_numbers)
In the original post I gave Mathematica code to find all sonnet primes. This post shows how to do it in Python.
CODE:
from sympy.ntheory import isprimefrom itertools import permutations
def number(t):
# turn a tuple into a number
return 10100000000000*t[0] + 1010000000000*t[1] \
+ 1010000000*t[2] + 101000000*t[3] \
+ 101000*t[4] + 10100*t[5] \
+ 11*t[6]
sonnet_numbers = (number(t) for t in
permutations(range(10), 7) if t[0] != 0)
sonnet_primes = filter(isprime, sonnet_numbers)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-752501/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- LeetCode-Count PrimesLeetCode
- leetcode刷題--Count PrimesLeetCode
- [LintCode/LeetCode] Check Sum of K PrimesLeetCode
- LeetCode筆記:204. Count PrimesLeetCode筆記
- Claude 3.5 Sonnet為何更擅長做碼農?
- LeetCode C++ 204. Count Primes【Math/Hash Table】簡單LeetCodeC++
- Anthropic 推出 Claude 3.5 Sonnet,稱新模型優於 GPT-4 Omni模型GPT
- SPOJ PGCD - Primes in GCD Table (好題! 莫比烏斯反演+分塊求和優化)GC優化
- 力壓GPT-4o!新王Claude 3.5 Sonnet來了,直接免費可用GPT
- 23個深度學習庫大排名:TensorFlow、Keras名列一二,Sonnet增長最快深度學習Keras
- 這些VLM竟都是盲人?GPT-4o、Sonnet-3.5相繼敗於「視力」測試GPT
- 奧林匹克競賽裡選最聰明的AI:Claude-3.5-Sonnet vs. GPT-4o?AIGPT
- 號稱擊敗Claude 3.5 Sonnet,媲美GPT-4o,開源多模態模型Molmo挑戰Scaling lawGPT模型
- Neuralink 將啟動第二例人類腦機晶片植入;多項 Claude 3.5 Sonnet AI 工具釋出丨 RTE 開發者日報晶片AI開發者日報
- 國產大模型參加高考,同寫2024年高考作文,及格分(通義千問、Kimi、智譜清言、Gemini Advanced、Claude-3-Sonnet、GPT-4o)大模型GPT
- 【python】python安裝Python
- 【Python】Python使用redisPythonRedis
- Python 之父談 PythonPython
- 【Python】python練習Python
- 【Python】python 日期操作Python
- python ----python的安裝Python
- python:python的多程式Python
- 【Python】Python連線mysqlPythonMySql
- Python 3 能振興 PythonPython
- 【Python】Python安裝模組Python
- 【python】python APScheduler 框架Python框架
- python學習之初識pythonPython
- Python 序列化(Python IO)Python
- Python合集之Python函式Python函式
- 【Python】python類的繼承Python繼承
- 小白自學Python(一) -- Python教程Python
- 為Python加速 - python+memcachedPython
- Python 3 正在毀滅 PythonPython
- Python補充06 Python之道Python
- [python]python錯誤集錦Python
- Python list of class attributes - PythonPython
- 【python】Python 3 的新特性Python
- python--- 之The program 'python' can be found in the following packages: * python-minimal * python3PythonPackage